Run scripts on startup Raspberry PI
- Create a bash script
sudo nano start.sh
Example:
#!/bin/sh
sleep 10
cd /
cd home/pi/
sudo python program.py &
cd /
sleep 10 is needed to load system respos first
- Change rights to 775
sudo chmod 775 start.sh
- Make a crontab
sudo crontab -e
- Make a log file to catch all the errors
mkdir logs
chmod 775 logs
- Add the following line to the crontab
@reboot sudo sh /home/pi/start.sh >/home/pi/logs/cronlog 2>&1
- Now reboot
sudo reboot