Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Last active April 27, 2017 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niraj-shah/fe4d394dad829b086089340ed1d07e48 to your computer and use it in GitHub Desktop.
Save niraj-shah/fe4d394dad829b086089340ed1d07e48 to your computer and use it in GitHub Desktop.
Process Checker Shell Script
#!/bin/bash
PIDFILE=/var/www/html/ajc.pid
if [ -f $PIDFILE ]
then
PID=$(cat $PIDFILE)
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]
then
# echo "Process already running"
exit 1
else
# Process not found assume not running
echo $$ > $PIDFILE
if [ $? -ne 0 ]
then
echo "Could not create PID file"
exit 1
fi
fi
else
echo $$ > $PIDFILE
if [ $? -ne 0 ]
then
echo "Could not create PID file"
exit 1
fi
fi
# command to run
php ajc.php >> ~/ajc.log
# remove PID file
rm $PIDFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment