I am currently piecing together a tool to work with Syslogs generated in my network, one of the requirements is to convert the DateTime from the format in which it is in syslog (%b %d %Y %T) to epoch. In essence, this is what I am trying to achieve:
Original Syslog format:
1: Jul 02 2019 15:14:19: %ASA-6-106015: <message>
2: Jul 02 2019 15:14:49: %ASA-6-106015: <message>
Final Log:
1: 1562080489 %ASA-6-106015 <message>
2: 1562080529 %ASA-6-106015 <message>
I know that I can do this by iterating through the entire log and performing a date -d operation. This is something I want to avoid. I prefer using GAWK time functions.
Here is my approach,
gawk -F: '{ print strftime("%s", timestamp}' syslog.log
But here the timestamp must be in the same format as the value returned by the systime() function. Which it isn't.
Also, I cannot use the mktime() function to convert syslog timestamp to the required format since it accepts input only if it is in a specific format [YYYY MM DD HH MM SS]
I feel there is a method to do this, but I am missing it. Any alternate methods will also be appreciated.
TZ=UTC
, but the result is 30 minutes off. – Jul 04 '19 at 14:34