-1

Help me in writing a shell script.sh to run my python service fin_code/final/Healthcheck.py by killing the current running service and run it again... This will be called in crontab to run for every 3hrs...

script.sh

kill -9$(ps grep 'healthcheck.py' | awk '{print $2}') nohup python fin_code/final/healthcheck.py &

I've used this script to run in crontab.

  • Despite the fact that you did get answers, I would be so bold as to suggest that you might get better answers in general, if you checked the syntax of the script you're writing, and took care to enter it accurately in the question, too. Right now, that doesn't seem to be even tested. – ilkkachu Jan 9 '18 at 17:41
0

It looks like you never give a try, but...

Edit /etc/crontab, for example:

nano /etc/crontab 

Then put your service in there:

* */3    * * *   root  bash /home/myuser/scripts/myscript 

Or the path and name for your script... The */3 will run it every 3 hours.

0

pythonRestarter.sh

#!/bin/bash
kill -15 $(ps aux | egrep 'fin_code/final/Healthcheck.py' | awk '{print $2}')
sleep 5
python fin_code/final/Healthcheck.py

Add pythonRestarter.sh in crontab with crontab -e as

* */3    * * * ./pythonRestarter.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.