Friday, June 4, 2010

FreeBSD 'watch' command

'watch' is a command I've been using for a few years and have recently discovered few people actually know about it. This command, unlike the GNU watch command, can listen in on and even interact with other terminal sessions.

I use this on my desktop a lot as it's connected to the TV. I ssh in, use 'watch' to connect to the relevant session and play video files with 'mplayer'. Of course it'd be easier to use 'tmux' or something similar but I always forget to start it up!


Using the 'w' command you can see all the terminals sessions on the machine:

$ w
3:22PM up 5 days, 18 mins, 4 users, load averages: 0.09, 0.03, 0.01
USER TTY FROM LOGIN@ IDLE WHAT
ash v0 - Sun03PM 5days xinit /home/ash/.xinit
ash pts/0 :0.0 Sun03PM 11 bash
ash pts/1 165.86.81.20 7:43AM - tmux: client (/tmp/tmu
ash pts/5 - 3:07PM 3 -bash (bash)


Here 'pts/0' is 'xterm' running on the desktop. So, to connect to it you have two options:

A read only session:
$ watch pts/0

An interactive session:
$ watch -W pts/0

To exit, type '^g'

If your screen goes blank and appears to lock up, you've probably tried to connect to your existing terminal. You can check this by tying 'tty', this will give you your current terminal device.

$ tty
/dev/pts/5

No comments: