Just make it @#$%ing work
- You want to print output of dmesg, constantly, immediately
- Dmesg is printing the kernel ring buffer (see
man dmesg)
- The kernel ring buffer is a special proc file,
/proc/kmsg (see man proc)
- Read
/proc/kmsg directly, ie cat /proc/kmsg.
Now, if you read the friendly proc manual, it'll sternly warn you to let only one user (who must be privileged) read /proc/kmsg at a time. Whatever syslog implementation you have should be doing this, and presumably it works with dmesg. I dunno, I'm out of my league here, just paraphrasing the manual. So while this is the "just make it @#$%ing work" way, consider the next couple methods first.
Man page approved: watch + dmesg
On Arch gnu/linux with systemd init, dmesg.log isn't written to very often, perhaps not at all? The best way I found to read the kernel log buffer continuously is with watch. Something like this should get you started (adjust for how many lines fit in your terminal):
watch 'dmesg | tail -50'
watch + dmesg + daemon + tail -f
A more convoluted solution might use watch to write dmesg output to file, which you could then tail -f. You'd probably want this running as a daemon. A proper daemon would also gzip and rotate logs. The following bash code is untested.
watch 'dmesg >> /var/log/dmesg.log | tail -1'
kernel.logdoes not contain the same output asdmesg. For example, for a damaged drive, file read errors indmesgspecify exactly which file could not be read, whilekernel.logunfortunately provides only the less-than-helpful notice:disk0s2: I/O error.– Ivan Vučica Oct 25 '11 at 17:41