Having a long running program that continuously writes to a logfile – how is it possible, disregarding any buffering issues, to add a date string to each line written to that file using a linux script?
I would imagine something like this:
tail -f logfile | ADD_DATE_TO_EACH_LINE > logfile2
The input would be something like that:
abc
def
ghi
jkl
The output should be similar to that:
2011-06-16 18:30:59 abc
2011-06-16 18:31:00 def
2011-06-16 18:35:21 ghi
2011-06-16 18:40:15 jkl
With perl:
With gawk:
Replace
commandwithtail -f logfilefor your specific example. Or, perhaps you could just redirect the original program’s stdout/stderr to the above pipe.