|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
[PLUG] date formatting in a shell script
|
I'm working on a script that will figure out average requests per
second and the max RPS for a web server. Unfortunately, the log file
doesn't put the date & time into a standard format.
Here are 2 lines from the tab separated log file (xxx where data was
but needs to stay anonymous such as IP, host, file, etc):
INFO 20080501043217440 00000000000000000005 9569 34353 0 tcpConnection-17000-6 xxx xxx xxx xxx xxx xxx - - 0 0 - 0 0 - 0 0 0 0 xxx
INFO 20080501043219725 00000000000000000006 7287 34353 0 tcpConnection-17000-7 xxx xxx xxx xxx xxx xxx - - 0 0 - 0 0 - 0 0 0 0 xxx
The date looks like it includes: YEAR MONTH DAY HOUR MINUTE SECOND
MILLISECOND (last 3 digits).
I can use awk to grab the 2nd field and load that into a variable, but
I'm brain dead on where to go from there. I want to end up with an
output such as 2008-05-01 04:32:17.440. From there, I should be able
to perform math operations on the dates.
I tried using the `date -d 20080501043217` without the ms field, but
it couldn't interpret it.
Any ideas on how to get the string into the format I want? I don't
want to do simple substitution (i.e. 2008 = 2008-, 05 = 05-) because
it should be generic enough to work on any date string in this screwy
format.
Thanks for any help.
Chad
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|