Enabling dmesg Timestamps in RHEL
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
i try, but , timestamps is not correct
chào anh minh,
em mới học lập trình android và muốn làm một cái ứng dụng nhỏ hiển thị thông báo trên mobile (push nofications). anh đã làm cái này chưa ạ? anh có thể giúp em không? mail em là khanhnguyen24188@gmail.com
example: date
Thu Mar 3 17:31:17 ICT 2016
log i see
[Fri Mar 04 03:50:13 2016] Enabled timestamps
[Fri Mar 04 03:52:41 2016] Enabled timestamps 222
[Fri Mar 04 03:58:00 2016] Enabled timestamps 333
dmesg timestamps are in UTC, while `date` usually shows local time, hence the time difference.