PC上装的ubuntu11.10,尽管echo 8>/proc/sys/kernel/printk.还好有dmesg命令,让我们知道内核运行的信息,但是每次dmesg会打印出一长串的字符,很多都是重复的信息,并不是我们想看到的增加的信息,怎么样才能实时地接受消息,而不用dmesg之后在里面找我们需要的信息呢?让shell给我们做吧:
#!/bin/sh LASTLINE_BAK=`dmesg | tail -1` while : do found=0 count=1 while [ $found -ne 1 ] do LASTLINE=`dmesg | tail -${count} | head -1` if [ "$LASTLINE" = "$LASTLINE_BAK" ]; then count=`expr $count - 1` found=1 else count=`expr $count + 1` fi done while [ $count -gt 0 ] do LASTLINE=`dmesg | tail -${count} | head -1` if [ $count -eq 1 ]; then LASTLINE_BAK=$LASTLINE fi echo "" echo -n $LASTLINE | sed 's/\[[. 0-9]*\]//g' | sed 's/^ //g' if [ $count -eq 1 ]; then echo "" fi count=`expr $count - 1` done sleep 0.1 done
在当前shell下demon运行此文件即可.