Some days ago I
registered an Aardwolf MUD account, and
want to show to my girlfriend about MUD and how to play it. So I
needed a method to copy the content of my terminal to hers, which I
called terminal broadcasting. I got help from the official
BBS of my college,
that I could redirect the output of the script program to the
target pt. The shell
command ran thus:
$ script /dev/null 2>&1 | tee /dev/pts/2
Where I assumed that the target pt
was /dev/pts/2.
Why was script functional? What I wanted was to duplicate
the content of my terminal to hers, both of which, in fact, were
file under /dev. So what I've got to do was to write
the content of /dev/pts/1 (I assume it's my pt)
to /dev/pts/2. Generally, for regular files, one can
just do a redirected cat like this
$ cat /dev/pts/1 > /dev/pts/2
But since /dev/pts/1 changes continuously, the command
above does not suit our needs. Furthermore, if we just redirect the
output, we ourselves are not able to see the content
of /dev/pts/1, which will make us unable to do any
thing in it. So quite natually, tee will be used. And for
the real-time-update stuff, we need a tool that gives us a subshell,
and "watch" all the input and output and err. It very seems that a
shell itself will do; however, unfortunately, a shell is too
low-leveled for this task, and script is the very program
(just see what script does: it write the content of
current pt to a file).
But the question is that why redirect? It seem a
simple script /dev/pts/2 will do it perfectly. Yes it
seems; however the answer is concerning the
"update continuously" thing: by default, script only
updates the file when encounter a line break (return), so we have to
use a pipe. If you really hate pipes and redirection, you can pass
a -f as an option like this:
$ script -f /dev/pts/2
It works similarly as using a pipe.
So for now we have two methods, and there is one more: using a
named pipe.
$ mkfifo temp.fifo
$ nc -l -p 1234 -c "cat temp.fifo" &
$ script -f temp.fifo
When others want to see your terminal, they can telnet you via
port 1234. This is a more robotic way.