Thursday, June 12, 2008

Shell script to monitor ur lab machines

Hello PPL,

After long time I addin new post. Below is the shell script using this can monitor server n their uptime.

[
#!/bin/bash

# add ip / hostname separated by while space
HOSTS="172.30.0.62 172.30.0.41 solaris netra1 172.30.0.76 172.30.0.114 aix"

# no ping request
COUNT=1

# email report when
SUBJECT="Ping failed"
EMAILID1="jack@knowlinux.com"
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "$myHost is not reachable"
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID1 $EMAILID2 $EMAILID3
fi
done
]