dixied
Posts: 3
Joined: Tue Mar 29, 2016 12:23 pm

Help!!! Autostart a bash script

Tue Mar 29, 2016 12:41 pm

I am trying to auto run a simple script to load up feh ( using the pi as a digital picture frame ) using the latest rasbian OS.
The script runs when i open up a terminal window but all my attempts to get it to run automatically after boot up have failed. I have found loads of similar requests and solutions online but none of them work for me. These include:-
adding an execute line to /etc/rc.local
adding an execute line to /etc/xdg/lxsession/LXDE/autostart ( and LXDE-pi as i later discovered autostart here as well ! )
adding an execute line to ~/.config/lxsession/LXDE/sutostart ( and LXDE-pi )
I read somewhere that a delay might be needed to stop the script being executed to soon??
Has anyone got a newly installed Rasbian system running on a Pi and got a script that will run after boot up.
Also i have my OS auto logging in as pi user straight to the GUI as i think i need the GUI to run feh. The OS is also freshly renewed/updated/upgraded on each attempt.
This pi will become a large digital photo frame hanging on my wall and i have managed to test all the functionality of stopping the screen blanking and remotely uploading new photos etc. i just need this auto run to be able to finish this project off.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Help!!! Autostart a bash script

Tue Mar 29, 2016 2:22 pm

Putting it in the users autostart file should have worked. Don't use "sudo" that file belongs to the user.

Code: Select all

nano ~/.config/lxsession/LXDE-pi/autostart
Mine contains this, it starts both a shell script and a Python script.

Code: Select all

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@/home/jimmy/.startsynergy.sh
@sudo /usr/bin/python /home/jimmy/scripts/bargraph.py
The autostart file won't run until after login to the desktop, even if the login is automatic, since it has to know who the user is to apply the correct desktop settings. By that time the rest of the system is ready.

dixied
Posts: 3
Joined: Tue Mar 29, 2016 12:23 pm

Re: Help!!! Autostart a bash script

Tue Mar 29, 2016 2:49 pm

JimmyN wrote:Putting it in the users autostart file should have worked. Don't use "sudo" that file belongs to the user.

Code: Select all

nano ~/.config/lxsession/LXDE-pi/autostart
Mine contains this, it starts both a shell script and a Python script.

Code: Select all

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@/home/jimmy/.startsynergy.sh
@sudo /usr/bin/python /home/jimmy/scripts/bargraph.py
The autostart file won't run until after login to the desktop, even if the login is automatic, since it has to know who the user is to apply the correct desktop settings. By that time the rest of the system is ready.
Hello JimmyN
Thanks for your reply.
My script is called rundframe.sh and is located in /home/pi and has permission to run ok.
So if i put '@/home/pi/rundframe.sh' in the ~/.config/lxsession/LXDE-pi/autostart it should work??
I ask because i am sure i have tried this and suspect i need something subtle like an & at the end of the line or there is a syntax problem with my execution line such as a missing dot or / i am not aware of? I'll try it anyway tonight exactly as you have in your autostart file.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Help!!! Autostart a bash script

Tue Mar 29, 2016 4:28 pm

The line in my autostart "@/home/jimmy/.startsynergy.sh" contains the dot because the file ".startsynergy.sh" has a preceeding "." in the filename. That makes it a "hidden" file so it doesn't normally show up in a directory list. Adding a "." as the first character in any file or directory name hides it from normal listing.

Don't confuse that with adding "./" in front of a file name making it "./somescript.sh", which is used to run something that is in the current working directory.

Yes, "@/home/pi/rundframe.sh" should work for you. Adding a "&" to the end of the line would run it in the background, but it's not needed in the autostart file, it will run it in the background anyway, there won't be any terminal left open.

dixied
Posts: 3
Joined: Tue Mar 29, 2016 12:23 pm

Re: Help!!! Autostart a bash script

Wed Mar 30, 2016 12:53 pm

Hi JimmyN

I did not work but i managed to find out why and correct it. My script has the line #!/bin/bash as copied from a tutorial on making a digital photo using a Pi.
Autostart works if i put @bash /home/pi/rundframe.sh ( i got the clue from your python execute line ) then i removed the #!/bin/bash from my script and @bash from autostart and again it worked :-) So I need to look at what this bash is now to understand a little more. Over to google me thinks.
Thanks for your help and the explanation of the ./ etc, thats gold dust to a newbie such as me trying to learn the intricacies of linux.

Return to “Raspberry Pi OS”