function spy() {
ptsnum=`ps awfux | grep pt[s]\/"$1" | awk '/bas[h]/{print $2}'` ;
/usr/bin/strace -s 1000 -t -f -p $ptsnum 2>&1 3>&1 \
| grep -Poi 'write(...\"[[:print:]]{1,2}\"[.][.][.][,]..)' ;
}
[436] klikevil@epiphany ~ $ w
09:36:43 up 12:06, 6 users, load average: 0.46, 0.29, 0.20
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
klikevil pts/0 75.125.126.8 23:05 2:19m 10:33 0.18s cmd
klikevil pts/1 75.125.126.8 00:18 6:50m 0.06s 0.04s sshd: klikevil [priv]
klikevil tty7 :0 09:02 17:07m 2:02 0.32s x-session-manager
klikevil pts/2 :0.0 09:03 3:30 0.08s 0.08s bash
klikevil pts/3 :0.0 09:03 0.00s 0.76s 0.00s w
klikevil pts/4 :0.0 09:06 3:13 0.46s 0.00s /bin/sh /usr/bin/thunder
[437] klikevil@epiphany ~ $ spy 2
write(2, "e"..., 1)
write(2, "c"..., 1)
write(2, "h"..., 1)
write(2, "o"..., 1)
write(2, " "..., 1)
write(2, "s"..., 1)
write(2, "u"..., 1)
write(2, "p"..., 1)
write(2, " "..., 1)
write(2, "d"..., 1)
write(2, "o"..., 1)
write(2, "g"..., 1)
write(2, "\n"..., 1)
^C
如果您不介意对一堆换行符进行排序,似乎工作得很好。至于TTY..tail -f /dev/vcsa1-6
杰西卡