Hi folks!!. I have one problem in my ping Perl script. I have open one ping process but this process has been taking count value as 1 even-though I have set it as 5
#!/usr/bin/perl -w
use String::Util 'trim';
=head1 NAME
ping_linux.pl - This script works on Linux system pings a host and re
+turns statistics data.
=head1 VERSION
Version 1.0
=head1 AUTHOR
Gaurav Dubey (gaurav.d@ronankiinfotech.com
=head1 SYNOPSIS
./ping_linux.pl [-c --> count (Number of echo requests to be sent)]
+[-i --> interval (Interval in milliseconds between echo requests)] [
+-s --> packetsize (Size of icmp packet)] [-h --> destinationIP (Ip ad
+dress of destination host)] [-w --> AllowableTime (Max time in second
+s for sending receiving echo requests/reponse)]"
=head1 DESCRIPTION
This pings a host via the system ping command and returns RTA ,Tx pack
+ets,Rx packets,TTL,Packet-loss
=cut
use strict;
use Getopt::Long;
use Pod::Usage;
my ($host,$count,$interval,$packetsize,$allowableTime,$p);
GetOptions(
"h|host=s", \$host,
"c|count=i", \$count,
"i|interval=i", \$interval,
"s|packetsize=i", \$packetsize,
"w|allowableTime=i",\$allowableTime,
);
#pod2usage("$0: No host given!\n") unless($host);
pod2usage("$0:No host given!\n") unless($host && $host =~ /^((([2][5][
+0-5]|([2][0-4]|[1][0-9]|[0-9])?[0-9])\.){3})([2][5][0-5]|([2][0-4]|[1
+][0-9]|[0-9])?[0-9])$/);
$count = 5 unless ($count);
$interval = 1 unless ($interval);
$packetsize = 64 unless ($packetsize);
$allowableTime = 1 unless ($allowableTime);
#print "\$count is : $count \n";
open CMD, "/bin/ping -c $count -i $interval -s $packetsize -w $allowa
+bleTime $host |" or die "Can't open ping: $!";
while (<CMD>)
{
print "$_ ";
}
close CMD;
Please do not suggest to use Net::Ping ,I am using system ping command for some reasons. So please help me .Yesterday it was working fine,don't know what happen today. Below I am showing my output
[root@localhost Perl_Ping]# ./sample2.pl -h 192.168.1.150
$count is : 5
PING 192.168.1.150 (192.168.1.150) 64(92) bytes of data.
72 bytes from 192.168.1.150: icmp_req=1 ttl=254 time=11.1 ms
--- 192.168.1.150 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 11.150/11.150/11.150/0.000 ms
Thanks,I wan to add 1 thing that through terminal its working fine
[root@localhost Perl_Ping]# ping 192.168.1.150 -c 5
PING 192.168.1.150 (192.168.1.150) 56(84) bytes of data.
64 bytes from 192.168.1.150: icmp_req=1 ttl=254 time=2.12 ms
64 bytes from 192.168.1.150: icmp_req=2 ttl=254 time=2.07 ms
64 bytes from 192.168.1.150: icmp_req=3 ttl=254 time=2.18 ms
64 bytes from 192.168.1.150: icmp_req=4 ttl=254 time=2.13 ms
64 bytes from 192.168.1.150: icmp_req=5 ttl=254 time=2.15 ms
--- 192.168.1.150 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 2.072/2.134/2.187/0.055 ms