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.
Asked
Active
Viewed 5.5k times
6

Shahbaz
- 169
- 1
- 1
- 6
-
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. – Aug 26 '11 at 12:03
-
Why "online" in the title? – Eric Oct 05 '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 07 '18 at 04: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 08 '18 at 08: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 09 '18 at 19:24
4 Answers
7
Have you tried tail -F
, eg.
tail -F /var/log/messages

ar.
- 1,154
- 6
- 3
-
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. – 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) – 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 – Aug 26 '11 at 14:09
-
1You 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
4
Two more modern methods:
dmesg -w
On systems with systemd journalctl
is also of interest:
journalctl --system -f

Gerald Schneider
- 23,274
- 8
- 57
- 89
3
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 removequiet

calandoa
- 1,285
- 2
- 12
- 14
2
You could use
cat /proc/kmsg
By this way you could get all kernel messages when they come