Adding messages to dmesg

James Young · January 1, 2013

The dmesg log on CentOS frequently is missing timestamps.  While it can probably be added, what I wanted to do was add a mark to dmesg every few hours so I’d know how the passage of time went with it.  This can be done with a simple cron job in /etc/cron.d, like this;

0 */6 * * *    root   /usr/local/sbin/dmesg-mark

Then make a script in /usr/local/sbin/dmesg-mark like this;

#!/bin/sh
/bin/date '+----- MARK %Y-%m-%d %H:%M:%S %Z -----' > /dev/kmsg

The above will output lines like this to dmesg;

----- MARK 2013-01-02 10:52:01 CST -----

You’ll get one of those in dmesg every six hours with that cron job.  The date format isn’t Australian standard (dd/mm/yyyy), it’s YYYY-MM-DD.  However, YYYY-MM-DD actually sorts properly.

Twitter, Facebook