How to Run Python Script on Startup in Linux
On scripting
Sometimes,we need to run python scripting manually when our linux machine doing any reboot.
This can be solved with adding the script to rc.local configuration.
this rc file will be run when we doing boot.
To know more about booting process you can read it here.
Ok,here is the step to add the script to rc.local file
For example,i have sd-agent python script for my monitoring stuff.
This file located at my root directory
I need to run the agent.py file everytime my machine start up.
So i will add the script agent.py to rc.local file
# edit the rc.local file
nano /etc/rc.local
# add the url path to the file,make sure you write them above the exit 0 line
cd /root/sd-agentpython ./agent.py start
Note : my agent.py script need to read the file config.cfg , so cd /root/sd-agent on the rc.local configuration is needed because config.cfg is located there.
# make sure the python script running on rc.local file
cd sd-agent
python agent.py stop
ps aux | grep agent
The script has been stopped.
Try to run the script via rc.local file,which is autorun when boot.
/etc/rc.localps aux | grep agent
Ok,so the script has been started when we run the rc.local file
Thank you,share if you like this article !
Hello.
ReplyDeleteI recommend you use full path to the python exec and with full path to the script - something like this:
/usr/bin/python /root/sd-agent/agent.py start
As result you have 1 command without cd need and in ps output you can see hull path for script.
Lucky!
Hi Yakymenko ,
DeleteYes of course,this is doable
we can replace the "cd" thing with fullpath to the script on the line 2.
Thanks for your input :)
RTP: High variance (RTP) slots - DrmCD
ReplyDeleteRTP: High variance (RTP) slots. Best 아산 출장안마 Casinos. 수원 출장샵 #1. Wild 거제 출장안마 Spins · 서귀포 출장안마 #2. King’s Bounty · #3. Divine 대전광역 출장마사지 Fortune.