Shell Keep Alive Script
Introduction
Simple shell script called from cron that checks and keeps motion running.
Detailed Description
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:
#! /bin/sh
# check that motion is running every 5 minutes
# result is zero if we find it running
ps -F | grep "\./motion"
if [ $? -ne 0 ]
then
echo "Motion not running, re-starting it"
/root/restart-motion
else
echo "Motion is running."
fi
exit 0