Hi guys,
I was trying to pipe two perl scripts
I have a data provider and a data process scritp.
First the data provider is
dhcp_line_dispacher.pl
#!/usr/bin/perl -w
use strict;
use File::Tail;
my $file = File::Tail->new(
name =>'/var/log/messages',
interval => 1,
maxinterval => 1,
# resetafter=> 5,
);
while (defined(my $line=$file->read)) {
print $line;
}
and , line_process.pl is:
#!/usr/bin/perl -w
use strict;
use Net::Ping;
my $result;
while (<>){
my $p = Net::Ping->new('icmp',3);
if ($_ =~ /^(.*) dns02cor dhcpd: DHCPACK on ([0-9\.]+)
+ to ([[:xdigit:]:]+).* ([0-9\.]+)/) {
for (my $i = 0; $i < 3; $i++){
print "attempt $i for $2 \n";
$result = $p->ping($2);
if ($result){
print "##############
+$2 is alive at attempt $i\n";
last;
}
$p->close();
}
unless ($result){
print "*****$2 is dead*****\n
+";
}
}
}
When I run them individually they work ok, but when I try to pipe them doing:
./dhcp_line_dispacher.pl | ./line_process.pl
Nothing happens.
So I test the ./dhcp_line_dispacher.pl and realized than I can`t grab the output.
For example from cli, I do:
./dhcp_line_dispacher.pl | grep ACK
And can not get the output in real time.
What should I do to get the output and then process it in other script?
regards,
Leo.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.