Wednesday, July 8, 2009

ITM Logs Timestamp Conversion

ITM v6 log files use a hexadecimal timestamp (to save space? who the hell knows), which adds unnecessary effort when the reason you're looking at the logs is to determine an issue in the first place. In any case... Here's the script I wrote when I first encountered the nonsense in ITM v6 logs a few years ago:

#!/bin/perl


 

foreach (<STDIN>) {

if (/^[^\s\d\w]+([\w\d]*)/) {

@t=localtime(hex($1));

$time=sprintf("%02d:%02d:%02d %02d/%02d/%04d",

$t[2],$t[1],$t[0],$t[4]+1,$t[3],$t[5]+1900);

s/^[^\s\w\d]+[\w\d]*/$time/;

}

print $_;

}

Here's a one-liner that Venkat.Saranathan at Gulfsoft.com cranked out, rending my script pretty much obsolete

perl -lane 'if ($_ =\ /^(.)([\dA-F]+)(\..*)/) { printf "%s%s%s", $1, scalar(localtime(oct("0x$2"))),$3; }'

No comments:

About Me

My photo
Been in the IT world since `92 (man, has it been over 16yrs already) and taken a real shine to scripting and web interfaces in 96 when someone showed me their HTML profile in Netscape. Most of my career has been involved with automation and sysadmin scripts in distributed environments. In 1998 became certifiable (sic) Tivoli Enterprise consultant; which focused on all aspects of my skill set, and kept me damned busy... still. My Tivoli consulting came through a couple of strong outfits { Crestone and Gulf Breeze } but am now working for myself as JDS Media. Not really a media company, but I liked the domain years ago.