linux - Perl script log to file, output lag -
i have perlscript logfile parsing , executes bash command:
$messagepath = `ls -t -d -1 $dir | head -n 5 | xargs grep -l "$messagesearchstring"\`;
i start perl script ./perlscript.pl > logfile.log
.
now tail on logfile watch progress, output gets stuck every time @ line described above. output stop there seconds , continue. ???
to profile problem wrapped this:
print `date`; $messagepath = `ls -t -d -1 $dir | head -n 5 | xargs grep -l "$messagesearchstring"`; print `date`;
the output shows command not consume lot of time:
so 6. okt 22:35:04 cest 2013 6. okt 22:35:04 cest 2013
if run script without redirecting output file there no lag.
any idea why?
i haven't tried duplicate behaviour, might stdout buffering problem. try with:
$| = 1; $messagepath = `ls -t -d -1 $dir | head -n 5 | xargs grep -l "$messagesearchstring"`;
update
i have tried duplicate behaviour observe: i've had make assumptions believe suspicion correct. here i'm piping, it's same redirecting file , tailing file:
./test.pl | awk '{ print strftime("%y-%m-%d %h:%m:%s"), $0; }'
without $| = 1
, output buffered , aggregated:
2013-10-06 23:08:27 saluton, mondo: /home/lserni/test.sh 2013-10-06 23:08:27 2013-10-06 23:08:27 waiting 10s... 2013-10-06 23:08:27 saluton denove!
with modification, each line printed generated:
2013-10-06 23:09:09 saluton, mondo: /home/lserni/test.sh 2013-10-06 23:09:09 2013-10-06 23:09:09 waiting 10s... 2013-10-06 23:09:19 saluton denove!
i expect script doing something takes seconds, , not generating messagepath
; , output delayed until perl has sizeable chunk of data send along, giving impression it's line that's stalling.
i forgot: timing pipe comes here.
Comments
Post a Comment