Skip to content

Instantly share code, notes, and snippets.

@sshine
Created November 25, 2012 04:23
Show Gist options
  • Save sshine/4142387 to your computer and use it in GitHub Desktop.
Save sshine/4142387 to your computer and use it in GitHub Desktop.
Printing at DIKU
#!/bin/sh
PRINTER=s2a
COPIES=1
ARGS=""
HOST=tyr
DRY=0
if ! opts=$(getopt -o p:n:r:h:fd24 -l fit,duplex,host:,range:,dry -- "$@")
then
echo "Usage: dprint [-p printer] [-n copies] [--fit] [--duplex] [-2 | -4]"
echo " [-h|--host hostname] [-r 1-5,7,13] [--dry]"
exit 1
fi
set -- $opts
while [ $# -gt 0 ]
do
case $1 in
(-p) PRINTER="$2"; shift;;
(-n) COPIES="$2"; shift;;
(--fit) ARGS="$ARGS -o fit-to-page";;
(--duplex) ARGS="$ARGS -o Duplex=DuplexNoTumble";;
(-2) ARGS="$ARGS -o number-up=2";;
(-4) ARGS="$ARGS -o number-up=4";;
-r|--range) ARGS="$ARGS -o page-ranges=$2"; shift;;
-h|--host) HOST="$2"; shift;;
(--dry) DRY=1;;
(--) shift; break;;
(-*) echo "$0: Unknown option $1. Error." 1>&2; exit 1;;
(*) break;;
esac
shift
done
for f in $*
do
f=${f:1:-1}
if [ $DRY -eq 1 ]
then echo "cat -- \"$f\" | ssh $HOST lpr -P $PRINTER -# $COPIES $ARGS"
else
echo "Printing $f..."
cat -- "$f" | ssh $HOST lpr -P $PRINTER -# $COPIES $ARGS
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment