this question is pretty fundamental but i didn't find the right words to google to find an answer
i want to start a presentation on a raspberry pi straight when it boots
So i tested the command to get it to open my presentation, i just used this command:
sudo libreoffice --impress --nolockcheck --nologo --norestore --show /home/pi/Desktop/Praesentation/1.pptx
that worked so i put that line into the autostart file at this path:
/etc/xdg/lxsession/LXDE-pi/autostart
That works fine but i found out that you should or can also use this command in the file:
#libreoffice --impress --nolockcheck --nologo --norestore --show /home/pi/Desktop/Praesentation/1.pptx
but running the command in the commandline with bash #libreoffice... does not work
What does the # mean?
I'm pretty sure you shouldn't be running LibreOffice as root (sudo). This will give it full rights to do anything on the system, which is not needed for an office application, and it might cause all sorts of trouble if it writes files owned by the wrong user.
The LXSession wiki explains what the # means:
autostart configuration file
This file stores the commands that will be executed at the beginning of the session. It is not a shell script, but each line represents a different command to be executed. If a line begins with #, the command following the # will be automatically re-executed if it crashes.
Related
I have seen many ways to launch a script like putting it in profile.D, rc.local, or creating a auto start file but none of those launch the file in a visible window if at all. I need it to be in a visible window in Ubuntu. I need to do this because I am using several emulators to stream to different services, and I don't want to have to start the script on each manually.
I am using visual box for the emulator. The sh file is on a removable drive because it is an external file. I also need it to run as sudo.
Edit: I don't actually need it to run at startup. I just need to have the script run. I can probably just sleep really long for graphic to load.
Edit 2: So I created a service that launched a sh file in /usr/bin/ which was supposed to create a gnome-terminal window that ran my script. It ran, however It didn't create a visible window for some reason. I then tried to specify a display which caused gnome to freak out. Dbus was not launching correctly. another question stated that gnome would not work because of how it was designed and stated to use konsole instead. Konsole also stated that it could not connect to a display, giving a QXcbConnection error. Konsole does not have an option to specify display. I don't know what else to try
Edit 3: So I did the thing in the comment. And the service works. However it only works after I run the file that the service runs in usr/bin manually after every restart. The important parts of the file:
#!/bin/bash
sleep 60
ufw disable
ssh nateguana#$(hostname) -X
xhost +
*launch Gnome**only works after file ran manually*
I have also tried exporting DISPLAY, and changing users with su. I have not tried importing SSHD, as another question said to do, as I think that is only for non local connections. I have also tried every single arrangement of commands possible. Xhost errors stating that it is unable to open display "".
You can use gnome-terminal -e <command> to spawn a new bash terminal which runs the command.
You could use something like
gnome-terminal -e /path/to/bashfile
Bear in mind, this will end the terminal after the bash scipt is done executing.
To avoid this,in a newline add $SHELL to the end of your bash script.
PS: the -e argument is deprecated and might be removed in later versions
I recently put together my first Raspberry Pi 3. I want to be able to safely shut down the Pi without corrupting the SD card. I found code online to shut it down:
sudo shutdown -h now
I'm wondering how to paste this into a new text file, and save that file so that it can be opened to shut down the computer, in the way that one can use a .bat file on windows to run commands.
It's running Raspbian.
Create a text file like this:
#!/bin/sh
sudo shutdown -h now
Save it under /usr/local/bin possibly with an extension ".sh"; perhaps the name could be "myshutdown.sh".
Then you must give execution permission to that file, with chmod +x "thatfile", or with a graphical tool.
Now you can type "myshutdown.sh" in a console, or make a link (launcher) from the desktop to that file.
Anyway, in unix and similar, "shell scripts" are the equivalent (but better) to m$ .bat files. They don't need to have a particular exstension, even if ".sh" can be nice; but they MUST have "execution permission" (given for example using chmod(1)). Also: the first line, "#!/bin/sh" is not always necessary, but it is best to use it.
I have a Windows dedicated server and I installed Multicraft to run Minecraft servers, and I wanted to add a accept EULA button, since I did not know much about bat files, so I found a sh file online and I did not want to use Cygwin because I don't know how to install it and make it run properly.
I want to change this to a .bat file:
#!/bin/sh echo 'eula=true' > "$SERVER_DIR/eula.txt"
it basically finds the line eula=false in eula.txt and changes it to true from what i understand
I would guess that this is what you're looking for:
echo eula=true>>%SERVER_DIR%\eula.txt
Given the double greater-than symbol it should append the line to the indicated file. Note that we're using a backslash here. You might want to look at the contents of that SERVER_DIR environment variable to see if it will work on a Windows-based computer.
If you want to mirror the behavior in the UNIX script then use a single greater-than symbol to overwrite the file content.
I have written a simple Shell script named decBright.sh that decreases my screen brightness by a bit every time I run it. However, I do not want to open the terminal and execute bash decBright.sh every single time.
Instead, I want to create some kind of executable file that I can place on my Desktop, which will run my script when it is double-clicked. One answer I found here on the askUbuntu forums did not work for me.
Is there some other way to do it?
I am using Ubuntu 14.04 (Trusty Tahr)
An executable in linux is a file with the executable bit on. Thus you simply modify it with chmod:
chmod +x decBright.sh
Then you can run it with:
./decbright.sh
You can also run it by double-clicking in many graphical linux distributions.
You also better provide a "Shebang": the first line of your script should specify the "interpreter":
#!/bin/bash
Or any other interpreter (at the first line of your file).
Originally I thought this was a db administration issue, but I think the lines have become a little blurred. I'm going to keep this strictly a scripting problem here. If you want more background info I posted this on ServerFault here:
https://serverfault.com/questions/511780/postgresql-pgdump-script-on-rhel5-failed-fe-sendauth-no-password-supplieddat
My Script
I distilled my original script down to this to keep things simple. This is what I have in a .sh named pg_dump_script:
/home/myusername/lappstack-1.2-5/postgresql/bin/pg_dump --host=127.0.0.1 --port=5433 --username=myusername mydbname
When I run this I get the following error:
$ bash pg_dump_script.sh
Password:
" does not exist database "corenection to database "mydbname
I can copy and paste the line in the script file and run it from the command line and everything works fine.
Here are the permission on the script file:
-rwxr-xr-x
I used chmod 755
I'm not sure what I'm doing wrong here? I'm not an expert on scripting, but I thought if I could run it from the console it would of course run fine from a script. Let me know if any information is needed. I'm trying to keep this simple.
Updates
I removed all parameters. This is all the text in the .sh
/home/myusername/lappstack-1.2-5/postgresql/bin/pg_dump
I receive this error:
$ ./pg_dump_script.sh
: No such file or directoryine 1: /home/myusername/lappstack-1.2-5/postgresql/bin/pg_dump
: command not foundst.sh: line 2:
Run dos2unix on your .sh file to convert to proper UN*X line endings and it should work:
dos2unix pg_dump_script.sh
When editing with vi check to make sure it's not in dos edit mode. If you start with an original text file with CR/LF in it, vi will automatically go into dos mode unless you tell it otherwise.