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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pinging IP addresses

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0

I have a script that does ping on my Solaris 7 OS but I need it to email me if an IP address does not ping.

I tried to use the Unix exit status to find unsuccessful exit status due to bad ping ($? = EXIT STATUS...IF 0 THEN IT SUCCEEDED, IF
OTHER THEN FAILED) then I would be able to email myself if an IP address didnt ping. My exit status check is not
working. Anyone have a better idea of how I could do this??


#!/usr/local/bin/perl
@a = (<DATA>);
$s = system(&quot;$?&quot;);
foreach (@a)
{
system(&quot;/usr/sbin/ping $_&quot;);
print system(&quot;$?\n&quot;);
if ( $? != 0)
{
print &quot;Could not ping host.&quot;;
}
else
{
print &quot;Ping successful.\n&quot;;
}
}
close(DATA);



__DATA__
111.111.111.111
222.222.222.333
232.454.556.565
 
Try this:

#!/usr/local/bin/perl
@a = (<DATA>);
foreach (@a)
{
$return = system(&quot;/usr/sbin/ping $_&quot;);
# might need this to get just the exit value. There is
# some other info in the return from system()
$exit = $return >> 8;
print &quot;$exit\n&quot;;
if ( $exit != 0)
{
print &quot;Could not ping host.&quot;;
}
else
{
print &quot;Ping successful.\n&quot;;
}
}
close(DATA);



__DATA__
111.111.111.111
222.222.222.333
232.454.556.565
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top