bartman's blog

live termcasting of your terminal over telnet

bartman
Table of Contents

I mentioned [earlier]{ubifs-on-sheeva} that I will be giving a talk at Flourish Conf next month. While preparing for the talk I decided to I wanted to share my terminal with the participants of the Workshop via telnet. The more popular alternative would be to use screen built in sharing, or maybe vnc, which would require more memory and CPU overhead… and additional accounts using the former method. I only have a SheevaPlug to work with, so I am trying to be as conservative as possible.

I was pointed to a blog post on termcasting by Joey Hess. Joey uses a modified version of ttyrec for termcasting. This will not work for me as I want people to watch the session live. While ttyplay seems to have some nice features, it exists as soon as it reaches the end of the recording… Whereas I want something similar to tail -f.

I ended up with a combination of script, tail -f and telnetd -L.

Here is the setup… #

First let’s start with capturing the session. My script is a bit more complex, but essentially it does the following:

script -c "TERM=vt220 screen -S termcast" -f "/tmp/termcast"

This will start a screen session, under script, and record all input and output to a file in tmp/termcast – more specifically anything echoed to the screen, so your passwords will not be shared. I discovered that vt220 works best when connecting from a windows system. This is one of the disadvantages of this method: you’re at the mercy of the terminal emulation capabilities of the client, and vt220 seems to be old enough that it’s supported by Windows.

Next, I created a script in /usr/local/bin/play-watch-log that contains:

#!/bin/sh
exec tail -f /tmp/termcast

The final step is to make telnetd run this script as the login shell; in /etc/inetd.conf, I placed:

telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd -L /usr/local/bin/play-watch-log

And we’re done. My students will connect to the session using telnet and be able to watch what I type… sweet!

“What about socat?” #

Shortly after I wrote this up, Wisq on the #oclug irc channel suggested I use socat.

Here is the replcement for inetd/telnetd using socat:

socat TCP-LISTEN:23,fork EXEC:"tail -f /home/watch/termcast/current"
Tags: