I have two different Python scripts I'd like to run at start-up on my Raspberry Pi A+. Both work perfectly if I run them via sudo python filename.py
. I can get the first one to run, but not the second one in the rc.local below. It doesn't matter if I switch them or not, only the first one runs, and only if I don't have &
at the end.
Here is my /etc/rc.local:
(Notice the commented-out version - it doesn't work either; but the hardware clock does...)
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
python /home/pi/ZBA_Timelapse/shutdown.py
python /home/pi/ZBA_Timelapse/ZBA_Timelapse.py
###python /home/ZBA_Timelapse/shutdown.py &
###(sleep 30; python /home/pi/ZBA_Timelapse/ZBA_Timelapse.py) &
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1_new_device
sudo hwclock -s
exit 0
EDIT:
I tried appending &
to the end of the line per SlySven's answer, but it still does nothing. Both Python scripts are infinite loop programs, so I thought I'd try another approach: a shell script. The newly tried rc.local:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
./home/pi/ZBA_Timelapse/startup.sh
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1_new_device
sudo hwclock -s
exit 0
startup.sh looks like this:
#!/bin/bash/
sudo python /home/pi/ZBA_Timelapse/shutdown.py &
sudo python /home/pi/ZBA_Timelapse/ZBA_Timelapse.py &
After both of those were set, I used sudo chmod +x /home/pi/ZBA_Timelapse/startup.sh
to make startup.sh executable and rebooted. After reboot I used cd ZBA_Timelapse
and ./startup.sh
to successfully test the shell script. It worked great. Both Python scripts executed and worked like they should.
I still had no luck on auto-starting both Python scripts on boot. What am I doing wrong here?
&
at the end of each execution so that both can run in parallel, ie, instead of your current lines, usepython /home/pi/ZBA_Timelapse/shutdown.py & python /home/pi/ZBA_Timelapse/ZBA_Timelapse.py &
Hope it helps. For more info on using&
in linux, read this question (and answers of course :P) superuser.com/questions/152688/…rc.local
, you should log the output of the command to see what is happening; I usually do this with an explicit subshell so(sudo foobar) &> /var/log/foobar &
. Which version of Raspbian are you running, BTW? If it is jessie I can give you an example of how to do this as a discrete service w/ systemd (which is sort of simpler than it is with sysv on wheezy).python /home/...
in the rc.local with(python /home/pi/ZBA_Timelapse/shutdown.py) &> /var/log/timelapse.log &
&(sleep 30 && python /home/pi/ZBA_Timelapse/ZBA_Timelapse.py) &> /var/log/timelapse.log &
The log file is empty after a reboot. And the python scripts still don't run.