this script checks to see if a program is running and starts it if it is not. if a certain time has passed the script will kill the running program
#!/bin/bash #location of script to monitor PROGRAM=‘myscript.php’ COUNTER=0 #!/bin/bash date2stamp () { date –utc –date "$1" +%s } # convert a date into a UNIX timestamp # time afterwhich script should not run finishtime=$(date2stamp "Thu Nov 1 15:22:00 MDT 2007") #echo $finishtime while [ 1 ]; do nowtime=`date –utc +%s` #echo $nowtime diffTime=$((finishtime-nowtime)) if ((diffTime > 0)); then echo "still time to go" else echo "TIME UP!: checking if running:" PROG_CHECK=`ps aux|grep $PROGRAM|wc -l` if [ $PROG_CHECK -gt 1 ]; then echo "running after time up" PROG_ID=`ps uax|grep $PROGRAM |head -n 1|awk ‘{print $2}’` #echo "KILLING" #kill -9 $PROG_ID else echo "not running after time up" fi exit 65 fi PROG_CHECK=`ps aux|grep $PROGRAM|wc -l` if [ $PROG_CHECK -gt 1 ]; then echo "running" else let COUNTER=COUNTER+1 echo "not running: starting: new log file: $COUNTER" /usr/local/bin/php /root/$PROGRAM & fi #time in seconds to sleep sleep 5 done