perl - print result from all devices on array -
i write script script print 1 result not results devices. belive error on print section couldn't figure out.
note :- host file has 30 devices list script print result of last device only.
#!/usr/bin/perl $host_file = "/usr/local/bin/test/host2"; open (packetloss,"$host_file") or die "cannot open extracted host file"; # put extracted data array @extracted_array=<packetloss>; chomp(@extracted_array); foreach(@extracted_array) { @words = split; $host = $words[0]; } $extracted_array[$ping_idx] = `/usr/sbin/ping -s -t 10 $host 56 2 2>&1`; $ping_idx++; ($packet_loss) = ($ping =~ m/packets received, (\d+)% packet loss/); ($round_trip) = ($ping =~ m/round-trip.*\(ms\).*min\/avg\/max\/stddev = \d+\.\d+\/(\d+\.\d+)\/.*/); print " $host $round_trip ms average latency , $packet_loss packet loss\n";
cause closing foreach , performing operation. should be
foreach(@extracted_array) { @words = split; $host = $words[0]; $extracted_array[$ping_idx] = `/usr/sbin/ping -s -t 10 $host 56 2 2>&1`; $ping_idx++; ($packet_loss) = ($ping =~ m/packets received, (\d+)% packet loss/); ($round_trip) = ($ping =~ m/round-trip.*\(ms\).*min\/avg\/max\/stddev = \d+\.\d+\/(\d+\.\d+)\/.*/); print " $host $round_trip ms average latency , $packet_loss packet loss\n"; }
Comments
Post a Comment