Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

python - Start shell script on Raspberry Pi startup

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...