user-avatar
Today is Friday
May 3, 2024

November 12, 2009

a shell script to check if a ipaddress is taken using ping

by viggy — Categories: tech — Tags: , , , Leave a comment

With the help of Abhas Bhaiyya, I could write this shell script which checks if an ipaddress can be pinged.

#!/bin/sh

if [ `ping -c1 192.168.31.31 >/dev/null; echo $?` -eq 1 ]
then
echo “not able to ping”
fi

/dev/null is used here so that the output of the ping command is not compared with 1.
$? gives out the return code of the command.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>