Note: How to run Python-script on startup
This is more or less a note to myself on how to run a Python-script on startup on a Raspberry Pi. If you follow my example, note that I have saved my Python script in a folder on the desktop. Change this to follow where you have saved your scripts.
Step 1: Make a launcher script
Start by open the Terminal Window.
In short, go to the folder you wanna place a the launcher script. It can be anywhere. Maybe the best place is to put it in the same folder as the Python script.
cd Desktop/Python/YashicaPi nano launcher.sh
This will launch a editor. Type in this script:
#!bin/sh # launcher.sh cd / cd home/pi/Desktop/Python/YashicaPi cd /
To save the script: Ctrl + X. The script work like this: it will navigate to the root. Then navigate to the folder where the launch script are located. At the end it will navigate back to root.
Now we have to make the new script executable.
chmod 755 launcher.sh
You can test it by run this command:
Step 2: prepare for logs
We make a folder for error logs for the crontab. Go back to root.
cd mkdir logs
Step 4: Add script to your crontab
Open crontab settings.
sudo crontab -e
Now enter this line inside the crontab
@reboot sh /home/pi/Desktop/Python/YashicaPi/launcher.sh >/home/pi/logs/cronlog 2>&1
Step 5: Reboot to see if it works