Wednesday, September 26, 2007

Ping Multiple Workstations and Mail Results

Here's a simple Z Shell script to check for network connectivity. If you have several dozen workstations, manually pinging each one can be a laborious task. This script pings (w/2 second timeout) and mails the results to a group alias. You can automate by scheduling it with a cron job.

# vi pinger.zsh
#!/bin/zsh

log=/tmp/log.`date '+%d%h%Y%H%M'`

echo >> $log
date >> $log
echo >> $log

for i in {1..30}
do
ping wkstn$i 2
if [ $? = 0 ]
then
echo wkstn$i up >> $log
else
echo wkstn$i down >> $log
fi
done
cat $log | mailx -s "Workstation Status: `basename $log`" groupalias@esofthub.com
#rm $log
:wq!

No comments: