Shell Keep Alive Script
Simple shell script called from cron that checks and keeps motion running.
In my setup I call this script every 5 minutes with a cron line like this:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /root/five-minutes.sh >/dev/null 2>&1
So name this script "five-minutes.sh" and don't forget to set it's permissions to 755 (do a chmod 755).
The reason I look for "./motion" is that I have two running versions of motion, the other one isn't all that important to me right now.
The "restart-motion" script is a simple script that changes to a special directory where I store my latest compiled version of motion and starts it from there, you can do what you want and/or just start motion directly from this script.
Here's the script:
# check that motion is running every 5 minutes
# result is zero if we find it running
ps -F | grep "\./motion"
if [ $? -ne 0 ]
echo "Motion not running, re-starting it"
echo "Motion is running."