Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Ping' script

Status
Not open for further replies.

071

MIS
Aug 9, 2000
153
Hi,
I'm trying to write a simple script to ping all of our servers....something in the line of

#/bin/ksh
ping XXX.XX.X.XX
ping XXX.XX.X.XX
ping XXX.XX.X.X
etc...

This script hangs on the first server that's down.

How can I get it to bypass the inactive servers and report on them at the end ??

Any help would be much appreciated.

 
Hi,

The default timeout value is 20 seconds, your script is using this value. You may try ping address timeout, where timeout may be set

eg ping 192.32.123.12 4

Hope this helps
 
That seems to have done the trick,
Thanks
 
Hi again !
Would it be possible to display a summary of the inactive servers at the end of the script ??


 
You can check the exit status of each ping command using the shell variable $?. 0 is a successful ping, non-zero (usually 1) is a failed ping. So you could do
Code:
ping XXX.XX.X.XX
[ $? != 0 ] && echo "Server XXX.XX.X.XX no reply"
This exit status check works for all shell commands.

Greg.
 
Thanks Greg,
But the script that I use already gives me a 'no answer' status for all inactive servers. Is there something I can add to get an overall summary of inactive servers at the very end of the script ? (Perhaps a 'grep' on no answer and 'awk' out the summary ?!)
 
well you can do the $? thing with ping xxx.xxx.xxx.xxx 4 > /dev/null
to clear up the output.

or else, you could write the output from the $? thing to a string, or a file, or do anything you want with it, and then output the lot at the end.
 
i have a question,

i would like to write a program that siply has 2 text boxes and a command button,

the first text box would be only one line high, and would be open so that a user can put in an IP/DNS address, and a command button for it to ping that address.

i would like the second text box to show the ping results.
could you help me with the code?

phly9
 
I've got this cgi script on my unix box - any good?

This is the HTML required :-
[tt]<A HREF=/cgi-bin/ping.pl>ping</A>[/tt]

And this is the script :-
[tt]
#!/bin/sh

PING=/usr/sbin/ping

echo Content-type: text/html
echo

if [ -x $PING ]; then
if [ $# = 0 ]; then
cat << EOM
<TITLE>Ping Gateway</TITLE>
<H1>Ping Gateway</H1>

<ISINDEX>

This is a gateway to &quot;ping.&quot; Type the desired hostname
(like hostname.domain.name, eg. &quot;net.tamu.edu&quot;) in your
browser's search dialog, and enter a return.<P>

EOM
else
echo \<PRE\>
$PING -c5 $*
fi
else
echo Cannot find ping on this system.
fi
[/tt]
One by one, the penguins steal my sanity.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top