Linux Date Command: Convert Named Stats Dump Date

by on March 11, 2010 · 5 comments· LAST UPDATED March 11, 2010

in

The rndc stats commands created /var/named/chroot/var/named/data/named_stats.txt file under RHEL 5.x or CentOS 5.x BIND 9 server. However, date is not is correct format. The date is in the following format:
grep 'Dump' /var/named/chroot/var/named/data/named_stats.txt
outputs:

+++ Statistics Dump +++ (1263408025)
--- Statistics Dump --- (1263408025)
+++ Statistics Dump +++ (1263408071)
--- Statistics Dump --- (1263408071)
+++ Statistics Dump +++ (1268304218)
--- Statistics Dump --- (1268304218)
+++ Statistics Dump +++ (1268304248)
--- Statistics Dump --- (1268304248)

How do I convert date (e.g., 1263408025) in a human readable format?

The number 1263408025 is seconds since 1970-01-01 and can be converted to a human readable format using the following simple date command:
$ date -d '1970-01-01 1263408025 sec'
Sample outputs:
Wed Jan 13 18:40:25 CST 2010
Your named stats was dumped on Jan/13/2010 at 18:40:25 local time.

More About UNIX Time

Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds. See wikipedia article for more information or refer to man page:
$ man date
OR
$ info coreutils date

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 5 comments… read them below or add one }

1 Marc March 11, 2010 at 12:04 pm

Also possible in Perl :

perl -e ‘print(scalar(localtime(1263408025)));’

Reply

2 unix March 11, 2010 at 1:24 pm

date -d ’1970-01-01 1263408025 sec’
is the same as
date -d @1263408025

Reply

3 Nerdoug March 11, 2010 at 2:23 pm

general Unix Timestamp conversion:

A) in bulk, in Excel:
Step 1: Put the timestamp in cell a1.
Step 2: In cell a2, enter “=a1/86400+25569″. Don’t enter the double quotes.
Step 3: Apply a new format to this cell by right-clicking on the mouse and choosing “Format cells” -> “Numbers” -> “Custom”.
Step 4: In the “Type” field, enter “dd:mmm:yyyy hh:mm”.

You can build a timezone adjustment into the formula. To generate Eastern Daylight time, which is a 4 hour offset, use the formula
“=(a1-4*3600)/86400+25569″
Using Excel is the most convenient method if you have a number of timestamps to interpret, especially if you can easily paste them into a spreadsheet and apply the formula to them all at once.

B) in awk, using strftime

for example, to make squid logs more readable:
awk ‘{print strftime(“%y%m%d %H:%M:%S “,$1)” “substr($0,17,999)}’ squidlog > nicer

This format makes it easier to extract stats for a given day, or hour.

Reply

4 Krieg March 11, 2010 at 7:48 pm

Excelente maestro.

Y sencillito…
… y sin ser argentino.

Reply

5 Florin March 11, 2010 at 8:32 pm

You can also do something like:

#!/bin/bash
while read line; do
  nix=`echo $line | awk '{print substr($5,2,10)}'`
  see=`date -d '1970-01-01 '$nix' sec'`
  echo "${line%(*}($see)" >> toto2
done < toto

To have the log file with the readable date.

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: