Posted on April 23, 2019 10:12 pm
 |  Asked by Nilesh Bhadane
 |  96 views
1
0
Print Friendly, PDF & Email

Hi,

I have written a simple python program which keeps writing message and date time to a file after a regular interval (5 sec).
I am running this program in the background from bash terminal.

python filename &

But after 4-5 hours this process is automatically gets killed.

How to make this process up all the time?

Thanks,
Nilesh.

1
Posted by Tamas Plugor
Answered on April 23, 2019 10:29 pm

Hi Nilesh,

Try “nohup python script.py &”
that should ignore the hangup signal and your script will keep running.

Thanks,
Tamas

1
Posted by Himanshu Singh
Answered on April 24, 2019 3:30 am

Hi Nilesh,

You can daemonize the script which means that the script will run and if it exits for some reason, EOS software will restart it. Also, this will be persistent across switch reboot.

Configuration example,
switch(config)#daemon time-script
switch(config-daemon-time-script)#command /usr/bin/python /mnt/flash/lan_solo.py
switch(config-daemon-time-script)#exit

switch(config)#bash ps -aef | grep -i lan_solo
root 1659 2084 0 03:09 ? 00:00:00 /usr/bin/python /mnt/flash/lan_solo.py

Also adding a note, daemonizing should be done only if the script has a main loop that runs forever.

HTH,
Himanshu

Post your Answer

You must be logged in to post an answer.