Adding messages to dmesg

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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.