Re: Watchdog script
Posted in 1996
My apologies for the quality of this post. I don't really have the time to clean it up and comment it nicely or even to make a real shar file. I would not normally post something this barebones, maybe next month I'll get a chance to clean it up. I'm sure that I could make some improvements in the ps call - but it's not a big enough deal. Actually I'm fibbing, I did clean up one or two things and I'm not going to test them - they're fairly no-brainer - but many the best laid plans.... Essentially add watchdog to your cron. It doesn't take up that much juice, run it every 15 minutes or so. Ah - I see we have it set to every 10 minutes BFD. Over the course of time we have learned about one or two processes which should be excluded from the possible list - notably an hpterm session can be owned by init - hence it's elimination. Anything it finds it writes to a temp file. When it's done it checks to see if the temp file has anything in it. If so It call alert_win which is a fairly generic window popper. It in turns checks who is on against who is listed in alrt_names and sends them windows. Of course those people have to have xhosted the machine on which all of this is occuring. Any questions holler. We use this basic construct in a couple of places to watch for different things. I did replace all of our specific directories (related to the application) with 'xxxx' - feel free to hack at will, or at Bob or Terry if you so feel like. cheers j. # Crontab entry: 10 * * * 0-6 /xxxx/watchdog # ============= watchdog (a VERY early jp effort) # Deamon to watch for runaways # algorithm = any ksh process owned by init (1) is a runaway - # notify the users in /xxxx/alrt_names # First of all, get a list of processes ps -ef | grep ksh | grep -v console | cut -c10-20 | while read "process" do # separate PID and PPID pid=`echo "$process" | awk cut -c1-5` ppid=`echo "$process" | cut -c7-11` if [ $ppid -eq 1 ] then # could be an hpterm session ps -fp $pid | grep -q hpterm if [ $? -eq 1 ] then # found one, get full ps on that process ps -lfp $pid fi fi done > /tmp/watch_msg # did we find any? if [ -s /tmp/watch_msg ] then echo "Potential runaway found" > /tmp/wmsg cat /tmp/watch_msg >> /tmp/wmsg msg=`cat /tmp/wmsg` /usr/local/bin/alert_win "$msg" # clean up rm -f /tmp/watch_msg /tmp/wmsg fi #================= alert_win #!/bin/ksh ###################################################################### # # alert_win - Notify programmers of monitored situation. # # JParker 11/17/93 ###################################################################### echo $1 > /tmp/alert_msg pgmrs=`who -q | grep -v ^#` # only those logged in fold_line $pgmrs | sort -u | while read x do pgmr=`grep $x /xxxx/alrt_names | cut -d"|" -f1` disp=`grep $x /xxxx/alrt_names | cut -d"|" -f2` DISPLAY=$disp export DISPLAY /usr/bin/X11/hpterm -e /usr/local/bin/alrt_w 2>/dev/null& done sleep 5 rm /tmp/alert_msg #================= alrt_w #################################################################### # # Alert window. Called by alert_win - in an hpterm window # #################################################################### tput bel tput bel tput bel pg /tmp/alert_msg #================== alrt_names jparker|hpbs3645:0.0 --- and here --- _____________________________________________________________________________ Jack Parker - Hewlett Packard, DMD/IS Boise, Idaho, USA jparker@hpbs3645.boi.hp.com _____________________________________________________________________________ "I'm with the IRS, I'm here to help you" _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________