Skip to main content
2 of 2
added 8 characters in body; edited title
peterh
  • 5k
  • 13
  • 34
  • 47

How to add a timestamp to bash script log?

I have a constantly running script that I output to a log file:

script.sh >> /var/log/logfile 

I'd like to add a timestamp before each line that is appended to the log. Like:

Sat Sep 10 21:33:06 UTC 2011 The server has booted up. Hmmph. 

Is there any jujitsu I can use?

Antonius Bloch
  • 5k
  • 8
  • 31
  • 42