Linux Date Command: Convert Named Stats Dump Date

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

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Marc Mar 11, 2010 @ 12:04

    Also possible in Perl :

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

  • unix Mar 11, 2010 @ 13:24

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

  • Nerdoug Mar 11, 2010 @ 14:23

    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.

  • Krieg Mar 11, 2010 @ 19:48

    Excelente maestro.

    Y sencillito…
    … y sin ser argentino.

  • Florin Mar 11, 2010 @ 20:32

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.