Monthly Archives: September 2007

Harry Potter shell script fan fiction, in celebration of my 35th birthday

When I have started multiple terminal sessions to server computers via SSH, I often run into problems when I forget that I have started a program in a different login session. Running pine multiple times is the worst, because of the little locking dance it does with the other pine sessions. Just thinking about it makes me unbearably sad, as if all the joy had drained out of the world. So, to defend myself against these ghostly login sessions, I now invoke the Patronus Charm:

[rbulling@tiamat:~/public_html/linux]$ patronus
Lumos!

Traversing floo network at pts/2, dementors spotted at:
pts/11
pts/5

Specialis Revelio!

Dementors found:
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
rbulling 18987  0.0  0.1  7000 2164 ?        S    10:45   0:00 sshd: rbulling@pts/5
rbulling 18993  0.2  0.0  5328 1372 pts/5    S    10:45   0:00 -bash
rbulling 19051  0.1  0.1  8048 2432 pts/5    S    10:45   0:00 elinks http://www.jkrowling.com/textonly/en/
rbulling 19105  0.0  0.1  7000 2148 ?        S    10:45   0:00 sshd: rbulling@pts/11
rbulling 19110  0.2  0.0  5332 1372 pts/11   S    10:45   0:00 -bash
rbulling 19173  3.2  0.1 12528 3472 pts/11   S    10:45   0:00 pine -i

EXPECTO PATRONUM!

[rbulling@tiamat:~/public_html/linux]$

After running this, all the processes associated with the other terminal sessions die, so you are left with one and only one working login session. Unlike issuing kill -HUP -1, the traditional way to deal with this problem, the patronus script will not harm processes associated with your current terminal session, or any daemon processes you may own. So, you can even run it safely as root.

The source code may be of interest to those of you use Linux, Mac OS X, UNIX, and to programmers.