Run your tcpstat
command in shell and pipe the output to your perl
script.
tcpstat -i eth1 -f icmp[0]==8 -o %C | perl script.pl
In this way, you should expect your input from <STDIN>
and remove the system
call in perl, of course.
Question
I am trying to run a tcpstat command that gives the output about number of icmp requests being received. and at the same time i need to check the count so that if it exceeds some threshold, a message should be displayed.
i tried out something like this
#!/usr/bin/perl
my @count= system "tcpstat -i eth1 -f icmp[0]==8 -o %C";
my $i=0;
while ($i<1000)
{
print "count of packets is :".$count[$i]."\n";
$i=$i+1;
if($count[$i]>50)
{
print "thats a lot of pings";
}
}
but it doesn't seem to work because.. the execution of the command doesn't end without an user interrupt...
is it possible to do that? running the command and simultaneously performing operations over its output?
Solution
Run your tcpstat
command in shell and pipe the output to your perl
script.
tcpstat -i eth1 -f icmp[0]==8 -o %C | perl script.pl
In this way, you should expect your input from <STDIN>
and remove the system
call in perl, of course.