#! /bin/sh # lwmon - monitor LaserWriter up/down status using 'atlook' # # usage: lwmon laseraddress mailaddress... # # also: entry in crontab file like - # 3,13,23,33,43,53 * * * * lwmon laser1:LaserWriter@zone user1 user2@host2 # # NOTE: assumptions: # (1) Laser printer names are unique across zones # (2) Laser printer names prefixed with "lwmon." are valid Unix file names # # Rex Sanders, USGS, November 1992 llw=$1 lw=`expr "$llw" : '\(.*\):.*'` shift users=$@ /usr/local/cap/bin/atlook -k "$llw" 2> /dev/null | \ if grep 'Net:.*Node:.*Skt:.*' > /dev/null then # lw is up, check to see if it was down if [ -f /tmp/lwmon."$lw" ] then # lw was down, send message and clean up day=`date '+19%y/%m/%d'` tim=`date '+%T'` echo >> /tmp/lwmon."$lw" echo "$lw UP at $day $tim" >> /tmp/lwmon."$lw" echo >> /tmp/lwmon."$lw" echo "Yippy!, lwmon@"`hostname` >> /tmp/lwmon."$lw" /usr/ucb/mail -s "$lw UP at $tim" $users < /tmp/lwmon."$lw" rm /tmp/lwmon."$lw" fi else # lw is down, Check again, maybe transient problem ( sleep 60 /usr/local/cap/bin/atlook -k "$llw" 2> /dev/null | \ if grep 'Net:.*Node:.*Skt:.*' > /dev/null then # lw is up, check to see if it was down if [ -f /tmp/lwmon."$lw" ] then # lw was down, send message and clean up day=`date '+19%y/%m/%d'` tim=`date '+%T'` echo >> /tmp/lwmon."$lw" echo "$lw UP at $day $tim" >> /tmp/lwmon."$lw" echo >> /tmp/lwmon."$lw" echo "Yippy!, lwmon@"`hostname` >> /tmp/lwmon."$lw" /usr/ucb/mail -s "$lw UP at $tim" $users < /tmp/lwmon."$lw" rm /tmp/lwmon."$lw" fi else # check to see if it has been down a while if [ -f /tmp/lwmon."$lw" ] then # lw was down, do nothing true else # lw just went down, send message and create log day=`date '+19%y/%m/%d'` tim=`date '+%T'` echo "So sorry, lwmon@"`hostname` | \ /usr/ucb/mail -s "$lw DOWN at $tim" $users echo "$lw down at $day $tim" > /tmp/lwmon."$lw" fi fi ) & fi