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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -