2015-09-24

Convert Unix Timestamps to useful Date Stamps from a pipe

I've found numerous times that I run into files that are in a format like:
[1443094172] [29058] SERVICE ALERT: imgserver03;Root File System;UNKNOWN;SOFT;1;ERROR: hrStorageDescr Table : No response from remote host '192.168.90.64'.
[1443094462] [29058] SERVICE ALERT: imgserver03;Root File System;OK;SOFT;2;Disk OK - / TOTAL: 15.748 Go USED: 19% : 3.019 Go

While I'm not that bad with reading timestamps... it takes some temporal awareness and when it's 6am and I haven't had my coffee yet, that's just too much cognitive power for me to conjure up. So I made the following script that takes info in from a pipe, looks for timestamps, and converts them over.


Save that in a file, chmod the file +x, and do something like:
cat mylogfile.log|./t2d

You can stick greps and such in there too. Just as long as the timestamp doesn't get corrupted, From the above output, I get:
$ cat mylogfile.log|./t2d
2015-09-24 07:29:32 [29058] SERVICE ALERT: dsfrcimg03;Root File System;UNKNOWN;SOFT;1;ERROR: hrStorageDescr Table : No response from remote host '10.93.90.64'.
2015-09-24 07:34:22 [29058] SERVICE ALERT: dsfrcimg03;Root File System;OK;SOFT;2;Disk OK - / TOTAL: 15.748 Go USED: 19% : 3.019 Go

I've also added this script in a public Gist on github.com: https://gist.github.com/thejml/7af9f4b56ef9b11e612f

No comments:

Post a Comment