use File::Tail;
my $log= '/abc.txt';
my $file = File::Tail->new(name=>$log,tail=>1);
while(defined($_=$file->read))
{
chomp ($_);
{system("echo '$_' ¦ nawk -f lacawk");}
}
and this is the file lacawk
BEGIN{
cell = "";}
#name of alarm
/ALARM/{
alarm=$0;
next;}
/STATE/{
printf("%s",alarm) >> test
next;}
if i run the command tail -f abc.txt ¦ nawk -f lacawk
the result is very fine. but it's not when i use the perl script. can any one have an idea? and why?
use File::Tail;
my $log= '/abc.txt';
my $file = File::Tail->new(name=>$log,tail=>1);
while(defined($_=$file->read))
{
chomp ($_);
print qx/echo '$_' ¦ nawk -f lacawk/;
}
but you may need to supply more of a path to nawk:
print qx/echo '$_' ¦ usr/bin/nawk -f lacawk/;
have you tried just the print & echo without piping into nawk to make sure you are really reading (from the log file) what you think it should be?
then try simplifying your nawk program to just printf before you add any text processing.
one small step at a time, so to speak...
sorry for the last lines ,, i didn't give in detail of my stiuation
my whole program is to read a logfile and filter the alarm of the hardware devices which is defined in few lines, and the name of the alarm and status of it in different line.
my point is the variable "cell" is a global variable, and it works in command: tail -f logfile ¦ nawk -f lacawk, it prints both the "cell" and "alarm".
but in perl script it understands and print only the variable "state" and leave the "cell" variable blank and i don't understand why is that? why it doesn't print "cell".