#! /bin/sh # atmon - monitor AppleTalk device up/down status using 'atlook' # # usage: atmon ATname mailaddress... # # also: entry in crontab file like - # 3,13,23,33,43,53 * * * * atmon laser1:LaserWriter@zone user1 user2@host2 # # Rex Sanders, USGS, October 1993 /* my first recursive shell script! */ PATH=$PATH:/usr/local/cap/bin touch /tmp/atmon.record atname=$1 shift users=$@ # # Check if device is up now # upnow=`/usr/local/cap/bin/atlook -k "$atname" 2> /dev/null | \ grep 'Net:.*Node:.*Skt:.*' ` # # If device is down, try again soon, one loop of recursion # if [ ! "$upnow" -a ! "$atmon_again" ] then (sleep 60 atmon_again=true $0 "$atname" $users ) & exit fi # # Check if device was down last time # wasdown=`fgrep "Device $atname down at" /tmp/atmon.record` # # Device was down, up now, send message and remove record # if [ "$wasdown" -a "$upnow" ] then now=`date '+19%y/%m/%d %T` (fgrep "Device $atname down at" /tmp/atmon.record echo echo "Device $atname UP at $now" echo echo "Yippy!, atmon@"`hostname`) | \ /usr/ucb/mail -s "$atname UP" $users fgrep -v "Device $atname down at" /tmp/atmon.record > /tmp/atmon.record2 cat /tmp/atmon.record2 > /tmp/atmon.record rm /tmp/atmon.record2 fi # # Device was up, down now, send message and add record # if [ ! "$wasdown" -a ! "$upnow" ] then now=`date '+19%y/%m/%d %T` (echo "Device $atname down at $now" echo echo "So sorry, atmon@"`hostname` ) | \ /usr/ucb/mail -s "$atname DOWN" $users echo "Device $atname down at $now" > /tmp/atmon.record fi