Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Enabling dmesg Timestamps in RHEL

Submitted by on June 12, 2015 – 5:04 pm 4 Comments

By default, CentOS/RHEL dmesg timestamps are disabled. Here are the instructions to enable timestamps and a quick script to display time in a human-readable format.

echo Y | sudo tee /sys/module/printk/parameters/time
echo "Enabled timestamps" | sudo tee /dev/kmsg

To make this change survive reboot, update /etc/rc.d/rc.local as shown below
cat << EOF >> /etc/rc.d/rc.local
echo 1 > /sys/module/printk/parameters/printk_time
EOF

And the script:
#!/bin/bash
date_format="%a %b %d %T %Y"
uptime=$(cut -d " " -f 1 /proc/uptime)
if [ "Y" = "$(cat /sys/module/printk/parameters/time)" ]
then
	dmesg | sed "s/^\[[ ]*\?\([0-9.]*\)\] \(.*\)/\\1 \\2/" | while read timestamp message
	do
		printf "[%s] %s\n" "$(date --date "now - $uptime seconds + $timestamp seconds" +"${date_format}" 2>/dev/null)" "$message"
	done
else
	echo "Timestamps are disabled (/sys/module/printk/parameters/time)"
fi

Save it as /var/adm/bin/dmesgt.sh; make it executable; and create a convenient link:
chmod 755 /var/adm/bin/dmesgt.sh
ln -s /var/adm/bin/dmesgt.sh /usr/bin/dmesgt

Result:
# dmesgt | tail -1
[Fri Jun 12 16:57:00 2015] Enabled timestamps

 

Print Friendly, PDF & Email

4 Comments »

Leave a Reply to Phạm Ngọc Minh Cancel reply

%d bloggers like this: