>>>>> "Andrew" == Andrew Specht <andrew@iaccess.com.au> writes:
Andrew> Hi, I was wondering if there is a script out there somewhere
Andrew> that converts the number in access.log (or store.log) to the
Andrew> date and time?
==========================CUT=HERE======================================
#!/usr/bin/perl -p
# Convert first field from seconds since epoch (%s) to %Y/%m/%d %H:%M:%S
s@^(\d+)@($sec,$min,$hour,$mday,$mon,$year)=localtime($1);
sprintf("%d/%d/%d %d:%d:%d",$year+1900,$mon,$mday,$hour,$min,$sec);@e
==========================CUT=HERE======================================
You can modify that to your prefered date format by editing the
sprintf() function call. Also, use gmtime() rather than localtime()
if you prefer UTC.
It assumes that the first characters of each line are digits
representing seconds since the epoch.
A slight variation that prints the time in ctime(3) format would be:
==========================CUT=HERE======================================
#!/usr/bin/perl -p
# Convert first field from seconds since epoch to Y/M/D/h:m:s
s@^(\d+)\.\d+@localtime($1);@e
==========================CUT=HERE======================================
Note how this version eats the fractional seconds, unlike the first
version. This suggests that one might prefer to use:
================================CUT=HERE============================================
#!/usr/bin/perl -p
# Convert first field from seconds.ms since epoch (%s.ms) to %Y/%m/%d %H:%M:%S.ms
s@^(\d+)\.(\d+)@($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($1);
sprintf("%d/%d/%d/%d:%d:%d.%d",$year+1900,$mon,$mday,$hour,$min,$sec,$2);@e
================================CUT=HERE============================================
were one pedantic.
Converting from cache.log's `%Y/%m/%d %H:%M:%S' format to %s is left
as an exercise for the reader.
-JimC
-- James H. Cloos, Jr. <cloos@jhcloos.com>Received on Thu May 14 1998 - 23:50:57 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:40:11 MST