Say I want to monitor memory usage on a java process overnight.
I can do something like
top | grep java > out.log
I will get a log file with a whole bunch of lines.
Is there an easy way to get a data/time inserted in front of each line?
Don't reinvent the wheel. Write the messages to syslog using logger(1), which is supported on just about every Unix flavor. Syslog will take care of the timestamps for you. Your log data will be stored to a system log like
Or, if you really want to write it to your own file. But then you need to clean up the file afterwards:
You could create something like
Don't forget to use