Skip to content

Convert UNIX timestamps to readable dates while viewing logfiles

As many admins know, logfiles are a cool thing. That is, if they are readable. Take for example the log written by Nagios.

$ grep restarting nagios.log 
[1423469372] Caught SIGHUP, restarting... 
[1423486879] Caught SIGHUP, restarting...

If you want to know the time of the restarts, you must convert the timestamps to a readable time. The Swiss-army-knife Perl and some RegEx know-how can do this easily.

$ grep restarting nagios.log | perl -pe 's/(\d+)/localtime($1)/e'
[Mon Feb  9 09:09:32 2015] Caught SIGHUP, restarting...
[Mon Feb  9 14:01:19 2015] Caught SIGHUP, restarting...

Trackbacks

Keine Trackbacks

Kommentare

Ansicht der Kommentare: Linear | Verschachtelt

Noch keine Kommentare

Kommentar schreiben

BBCode-Formatierung erlaubt
Standard-Text Smilies wie :-) und ;-) werden zu Bildern konvertiert.
Formular-Optionen