I'm trying to create a simple network monitoring tool with perl.
I've tried Net:Ping and it works but for some reason isn't successfully pinging my all my devices. ( I've tried rebinding, changing timeouts... etc) so I've resorted to using system ping (solaris)
I'm trying to get the pings out and complete as fast as possible so I'm calling a system command with "&" and for some reason the program isn't getting the correct exit statuses.
If I remove "&" everything work correctly, but takes minutes to run instead of seconds
use Time::HiRes qw( time ); $MDIR="/tmp/"; #save list into an array open(LIST, "$MDIR/list"); @list=<LIST>; close LIST; @updevices=grep(!/known down|unmanaged/i,@list); my $start = Time::HiRes::gettimeofday(); foreach $element (@updevices) { #hostname:status:ip @ip = split(':',$element); system("ping $ip[2] 1 &"); $result = $?; print "ping $ip[0] $ip[2] $result\n"; if ( $result != 0) { print "$ip[0] is dead\n"; } } my $end = Time::HiRes::gettimeofday(); printf("%.2f\n", $end - $start);
In reply to Problem with exit status of bash script by dizzyd719
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |