shell script for ping

hi anyone,

i want shell script for ping command.

any one post here............

Something like:

ping

i know...

but i want entire program....

I know you know. I know too :smiley:

My answer was a vain attempt at humour.

From your question is utterly impossible to know what you want.

What "entire program"? To do what?

Which Operating System and version? The syntax for "ping" varies widely.

solaris and aix

i don't know exactally ver?

Are you, perhaps, under the assumption that 'ping' is a shell script? If so, we have to disappoint you, as it's a binary program with widely different code across OS', probably written in C on most.

This is what i got for you in my archive which i used it in AIX quite long time ago, i hope it helps you...

# cat host
150.150.102.10
150.150.105.10
150.150.106.10
150.150.150.150
# cat pn
while read hostname
do
PL=$(ping -c 10 $hostname | grep "% packet" | awk '{gsub("%","",$0);print $7}')
 if [[ $PL -gt 50 ]]
  then
  echo "$hostname is not pinging" >> status
  else
   echo "$hostname is pinging" >> status
  fi
done < host
# cat status
150.150.102.10 is pinging
150.150.105.10 is not pinging
150.150.106.10 is pinging
150.150.150.150 is not pinging
#

on Solaris, I found this,

bash-3.00$ uname -a
SunOS your_host 5.10 Generic_127111-11 sun4u sparc SUNW,Sun-Fire-V440
bash-3.00$ /usr/sbin/ping your_host
your_host is alive
bash-3.00$ echo $?
0
bash-3.00$ /usr/sbin/ping invalid_host
/usr/sbin/ping: unknown host invalid
bash-3.00$ echo $?
1
bash-3.00$ 

you can have something like this:

/usr/sbin/ping your_host >/dev/null 2>&1
status=$?
if [ "$status" -eq "0" ]; then
 echo "ping success"
else
 echo "ping failed"
fi

Are you planning to create something that will check the state of the servers?
I mean if it is pingable is up if not is down?

Ping varies over platforms and versions, but it tends to return a code that is reliable to consistent so that 'if ping ${target}' works.

You do need to be more clear and complete with such questions.