Shashikant shah

Thursday, 13 November 2014

BASH Script for service check

  
#!/bin/bash
PIDFILE=/tmp/phonemonitor.pid
PHPSCRIPT=/usr/local/phonemonitor/monitor.php
echo 'Checking if our monitor script is active'
if [ -f $PIDFILE ] ; then
    PID=`cat $PIDFILE`
    if ps ax | grep -v grep | grep $PID > /dev/null
    then
        echo "Script is running"
    else
        echo "Script is not running - attempting to Start"
        rm -f $PIDFILE
        php $PHPSCRIPT & echo $! > $PIDFILE&
    fi
else
    echo "Script is not running - attempting to Start"
    php $PHPSCRIPT & echo $! > $PIDFILE&
fi

No comments:

Post a Comment