Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: batch ping problem

by Henri Icarus (Beadle)
on Jun 13, 2001 at 19:27 UTC ( [id://88089] : note . print w/replies, xml ) Need Help??


in reply to batch ping problem

Derek,

There are a number of errors in your code. For one, you are opening PINGIN inside the loop but only closing it outside the loop. Also your regular expression search when looking throught the log is missing a * so it will never match (it should be "([0-9.]*)" )

Finally I think you've got the case wrong, because ping returns the 64 bytes line when machines are available!

All that aside, there's a much easier way to do what you're trying to do, just use the backtick operator, like this:

$ip = "10.32.$octet3.$x"; @data = `ping $ip -w 5`;
That will load the results of the command into an array which you can then process with a single grep command:
print "$ip is not available" if !grep(/^64 bytes from/,@data);

Enjoy!

-I went outside... and then I came back in!!!!