Want to do something like

dmesg | tail -f

but it doesn't work: I use Mac OSX 10.6.7, by doing that the tail will exit, instead of monitoring the output.

I wonder if there is any way to do it, or any equivalent command. P.S., I don't think a while loop will be a good enough idea.

link|improve this question
that works fine on my Ubuntu 10.04LTS box. A workaround would be to tail whatever logfile that syslog is putting kernel messages into. – Anonymous May 26 '11 at 21:58
1  
On Mac OSX, that file is /var/log/kernel.log – Anonymous May 26 '11 at 22:01
@Marc Sorry I added my machine spec now. @bobDevil That is cool, but seems that the output is different from dmesg. However this one looks nicer – Ivan Z. Xiao May 26 '11 at 22:06
@Anonymous 2: Unfortunately, kernel.log does not contain the same output as dmesg. For example, for a damaged drive, file read errors in dmesg specify exactly which file could not be read, while kernel.log unfortunately provides only the less-than-helpful notice: disk0s2: I/O error. – Ivan Vučica Oct 25 '11 at 17:41
feedback

migrated from stackoverflow.com May 27 '11 at 3:00

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 7 down vote accepted

You are probably looking for some combination of messages from various log files. Try:

tail -f /var/log/{messages,kernel,dmesg,syslog}

…to get a pretty good overview of the system. If you want more or less than that, research what log file the messages you want to see are being placed in.

Also look into using multitail to file and color code and filter multiple log files at once.

link|improve this answer
1  
Thanks for the heads-up re: multitail. Looks interesting. In the case of OS X it'll be something like: tail -f /var/log/{system.log,kernel.log}. – boehj May 27 '11 at 3:21
system.log and kernel.log do not contain the exact output of dmesg on OS X. For example, for a damaged drive, file read errors in dmesg specify exactly which file could not be read, while kernel.log unfortunately provides only the less-than-helpful notice: disk0s2: I/O error. – Ivan Vučica Oct 25 '11 at 17:45
feedback

Just make it @#$%ing work

  1. You want to print output of dmesg, constantly, immediately
  2. Dmesg is printing the kernel ring buffer (see man dmesg)
  3. The kernel ring buffer is a special proc file, /proc/kmsg (see man proc)
  4. 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'
link|improve this answer
OS X does not have /proc, however the rest of your answer is applicable. watch can be installed from MacPorts: macports.org – Ivan Vučica Oct 25 '11 at 17:44
@Ivan Vučica Ah, good to know. Wonder where OSX represents the kernel ring buffer.. – djeikyb Oct 27 '11 at 22:49
1  
Looks like it's directly in the kernel memory. Source code for Apple's dmesg implementation: opensource.apple.com/source/system_cmds/system_cmds-230.7/… Quick Googling doesn't mention anything about it being represented in the filesystem :/ – Ivan Vučica Oct 28 '11 at 9:24
feedback

you might be able to do:

tail -f /var/log/messages
link|improve this answer
2  
On most systems, the dmesg log file is just a static dump of the dmesg buffer after system boot completes. After that, any new kernel messages usually go into another log file and the dmesg file will stay unchanged until reboot. – Anonymous May 26 '11 at 22:08
1  
I don't know about "most" systems, but none of the GNU Linux systems I admin behave that way. dmesg reports a current set of the latest messages from the kernel, usually specific to the hardware subsystems. – Caleb May 27 '11 at 7:26
feedback

This may work for you

while true;do sudo dmesg -c;done

Keep in mind that the '-c' flag clears the message buffer into stdout. The 'sudo' is unnecessary if you are root. If you feel this is eating too much of your CPU resource, try adding a 'sleep 1' before the loop is done.

link|improve this answer
watch might be good there, if you are watching the screen all of the time – Seth Robertson May 26 '11 at 22:07
1  
Feel free to cite your sources: linuxforums.org/forum/applications/… – Anonymous May 26 '11 at 22:08
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.