Topic: How to turn the hexa date in the log to something human readable(bash)
hellu all,
in the log written by the server, you get the date in an hexadecimal format, which is quite annoying for certains purposes. Working on some bash scripts, I got to find out a way to made it human readable. Here is one solution.
Example (don't pay attention to the error ) :
[52814340][server]: couldn't open socket. port 8303 might already be in use
We want to turn 52814340 to something, we, human can understand.
Let's pretend you have a log file nammed server.log
# this is just to grab the first line of the log and then the hexa date of this line, don't pay attention to this
HEXA_DATE=$(tail server.log | head -1 | awk -F ']' '{ print $1}' | tr -d '[')
# or (same result)
HEXA_DATE=52814340
# here is how to convert
date -d @$(echo $((0x${HEXA_DATE}))) +'%F %T'
which gives => 2013-11-11 21:51:12
P.S: i'm not so sure if I posted this in the good section nor if this post is interesting, but well enjoy if it helps you
edit: forgot to write the result
<3