2

I have a kernel module logging input of some sensor while I work with it. I want to see if there is a command that outputs /var/log/messages (for example) but waits for more logs to come. That is, some program like dmesg except that it stays on and keeps printing newly-come logs.

  • Of course, I can always write a user space program, and read the value from some shared memory or /proc file etc, but I am just asking this question out of curiosity. – Shahbaz Aug 26 '11 at 12:03
  • Why "online" in the title? – Eric Oct 5 '18 at 11:50
  • @eric, some people would say "view it in realtime". But realtime has a precise meaning and this is not it. Online is the word used to mean right then and there, but without time guarantees. For example "this robot is making these decisions online" when it's doing it "on the fly", but it's not realtime. – Shahbaz Oct 7 '18 at 4:10
  • "realtime" is better indeed, and "live" or "as they're generated" or "log stream" is even better. There are many options available. – Eric Oct 8 '18 at 8:09
  • @eric, like I said realtime is wrong (although a common mistake), but I could go with live. I see how online would be confusing outside the robotics world. – Shahbaz Oct 9 '18 at 19:24
5

Have you tried tail -F, eg.

tail -F /var/log/messages
  • Thanks that's what I wanted. I read the man page for tail but the part for -f was not at all understandable to me. – Shahbaz Aug 26 '11 at 12:08
  • @Shahbaz : Be careful if you are looking at a file that is log rotated, i.e. logs are automatically archived, like syslog.0, syslog.1.gz etc.. As soon as the file you watching is rotated, you won't see any new lines. You have to restart tail -f. (At least this is the case on my system) – Xavier T. Aug 26 '11 at 12:33
  • @Xavier T. Thanks. I was just doing this for a small test however to see if my driver worked – Shahbaz Aug 26 '11 at 14:09
  • 1
    You can of course use the tail -F command which watches for changed/rotated files and continues to watch the file with the given name. – ar. Aug 26 '11 at 14:38
2

You can:

  • execute dmesg every second: while true; do dmesg -c; sleep 1; done
  • print everything appended to /var/log/messages: tail -f /var/log/messages
  • dump the logs on the serial port and read them on another PC. You will need to add to your kernel boot parameters: console=ttyS0,115200 console=tty0 ignore_loglevel and remove quiet
2

You could use

 cat /proc/kmsg

By this way you could get all kernel messages when they come

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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