Monday, March 28, 2011

How to write a simple script to do a ping check using bash scripting

Advertisements

This script will work in all linux/unix operating systems like Redhat, Fedora, Centos, Solaris, Ubuntu, Debian etc, if they are having bash shell or sh.
First we have to set a variable status and an IP to check.

See the example given below :

#!/bin/bash
#Purpose : TO check whether a system is up and working or not using a simple ping check.
IP=192.168.0.21
status=1
until [ "$status" -eq "0" ]
do
        ping -c 1 $IP > /dev/null
        status=`echo $?`
                if [ "$status" = "1" ]

                then
                        echo "The machine $IP seems to be down!"
                else
                        echo "The machine $IP is up"
                fi
done

No comments:

Post a Comment

Be nice. That's all.