GDC Print

UT’s computer science building, the GDC, gives free printing1 to CS students. The one caveat is that the printing interface is not straightforward: you either have to log on to a physical machine or ssh into one to issue a print command, and getting the file you want to print onto a lab machine is another step.

Anyway, I automated the process. There is a directory on my computer called To-Print, and whenever a file is moved there, a script fires that prints the file at the GDC. Two scripts are used to achieve this—one to do the actual printing (gdcp):

#!/usr/bin/env sh

set -eu

id="$HOME/.ssh/id_rsa"
remote="$CSID@$LABMACHINE.cs.utexas.edu"
ext="${1#*.}"

scp -i "$id" "$1" "$remote:~/to-print.$ext"
ssh -i "$id" "$remote" "lpr -Plw27 to-print.$ext; rm to-print.$ext"

And a daemon that monitors the To-Print folder (gdcpd):

#!/usr/bin/env sh

set -eu

prdir="$HOME/Downloads/To-Print"

inotifywait -m "$prdir" -e modify -e moved_to |
    while read -r dir action file
    do
        gdcp "$dir$file"
        rm -f "$dir$file"
    done
  1. For CS-related material only, which is of course the only thing I use it for