#!/bin/ksh ################################################################################ # # File to loop while a pattern exists, does SOMETHING when it is missing. # # Written by Matt Baker mbaker@computeranddata.com # ################################################################################ LOGFILE=/tmp/watchdog.log.$$ SLEEPTIME=5 # # pattern is case sensitive (this could be changed in the grep with a '-i') # PATTERN=hello echo "$0 started on: $(date)" > $LOGFILE # # while PATTERN exists, loop on some commands # while (( $(ps -eo comm,args |grep -c $PATTERN | grep -v "grep grep") )) do echo "----------------------------------------------------------------" # # commands to do while it is still running (if any) # date ps -elf finger -i;who -lu sleep $SLEEPTIME done >> $LOGFILE # # process PATTERN is no longer there, do finish commands and exit # # could add paging and/or email process here # echo "----------------------------------------------------------------" >> $LOGFILE date >> $LOGFILE last >> $LOGFILE echo "$0 stopped on: $(date)" >> $LOGFILE echo "Watchdog barked! Closed logfile: $LOGFILE"