Here are some ideas for limited environments
Environments such as embedded or pre-boot, where watch, tail, cat, dd and other commands might not be available, might need different gymnastics.
This is what some lightweight Linux distributions do:
while dmesg -c >> /tmp/dmesg.log; do sleep 0.1; done & tail -f /tmp/dmesg.log
It backgrounds the while loop (with &) while tailing the generated output.
If you can't write to /tmp:
mount -t tmpfs - /tmp
mount -t ramfs - /tmp
# or use /dev/shm instead of /tmp - which is available in newer environments
If you don't have tail, you can
dd if=/tmp/dmesg.log 2>/dev/null
Or you might be in a busybox environment that doesn't have dmesg linked, then just:
busybox dmesg -c
You might also need to
instead of sleep
If you don't have sleep:
while dmesg -c; do echo >/dev/null; done
If you don't have "dmesg":
while sleep 0.1; do cat -v /proc/kmsg; done
This only works if nothing else is reading from here. You might also have a /dev/kmsg.
If you don't know what you have, and you don't have "ls", just:
# or simply:
kernel.logdoes not contain the same output as
dmesg. For example, for a damaged drive, file read errors in
dmesgspecify exactly which file could not be read, while
kernel.logunfortunately provides only the less-than-helpful notice:
disk0s2: I/O error.
sudo dmesg >> "$TMPDIR/dmesg.log"; tail -f "$TMPDIR/dmesg.log"on Mac.