Jan 07 2009

Shell script for checking a sytem alive or not

Category: Shell ScriptsBipin Balakrishnan @ 6:08 pm

It is necessary in certain cases we need to check whether the system  or server is alive and if we want some alert like email or sms to inform you that the system is down.We can do it by a simple shell script .All we need is to install a package call fping

fping  is a program like ping which uses the Internet Control Message Protocol (ICMP) echo request to determine if a target host is responding.  fping differs from ping in that you can specify any number of targets on the command  line,  or  specify a file containing the lists of targets to ping. Instead of sending to one target until it  times out or replies, fping will send out a ping packet and move on to the next target in a round-robin fashion.
installing command

sudo apt-get install fping

Script:

#!/bin/sh
status=`fping 192.168.1.22 | cut -d ' ' -f 3`
if [ $status != "alive" ]
then
echo 'system is down' //Here use your alert as you like email, sms, voice alert etc
fi

Will check the system with IP 192.168.1.22 alive or not.Put it as a cron job and schedule the time interval to automatically check system status and get the alert…:)

Tags: ,