I have a python program which posts to my local web server. The script runs on a raspberry pi running the latest version of raspbian 3.18. How can I make the Python script run at startup? Raspbian has a login password which is the first thing I have to remove. If the power ever goes out I want the pi to reboot and start running my script again. Should I be using Raspbian for this? The script is the only thing the pi is used for. I tried adding the script to /etc/init.d but I do not think it will run either way if the pi requires login info upon booting.
-
2stackoverflow.com/a/12973826/3745735user3745735– user37457352015-05-28 12:58:59 +00:00Commented May 28, 2015 at 12:58
-
Thanks but im not sure if that will run the program without having to login. Can someone confirm this?Sam Munroe– Sam Munroe2015-05-28 13:12:13 +00:00Commented May 28, 2015 at 13:12
-
1Zudo's link will work without the need of login inUser404– User4042015-05-28 13:14:17 +00:00Commented May 28, 2015 at 13:14
-
I tried all the steps in the link above and it still did not workSam Munroe– Sam Munroe2015-05-28 13:32:02 +00:00Commented May 28, 2015 at 13:32
2 Answers
You can use the Linux crontab to run the Python script. Let's go to root and create a shell script.
sudo -i
nano startup.sh
Then type your python script on this bash script. navigate to home directory, then to this directory, then execute python script, then back home.
cd /
cd home/pi/your directory
sudo python yourpythonscript.py
cd /
Save the script and then exit. Make this sh script executable by giving it permission.
chmod 755 startup.sh
Now open and edit rc.local file.
nano /etc/rc.local
Add /root/startup.sh & before exit 0
now save and exit from the file and reboot your pi.
sudo reboot