Sunday, June 7, 2015

RaspberryPi Crontab run bash script for python in every 30 min

I wrote a bash script to check python program is running. If it's not running send me an email and start that program. After a quick research I found the solution:

creating Bash Script:
----> checkProgram.sh

#!/bin/sh
SERVICE='python'
 
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
    echo "$SERVICE service running, everything is fine"
else
    #echo "$SERVICE is not running"
    python /home/pi/receive.py &
    echo "$SERVICE is not running!" | mail -s "$SERVICE down" root
fi

CronTab:

-> crontab -e
-> */15 * * * * /home/pi/checkProg.sh
-> /etc/init.d/cron restart
This will run the program for every 15 min.


No comments:

Post a Comment