Listing 5. Filter to Recognize Printer Types
#!/bin/sh
# filter script for text, Postscript
# or TIFF printing.
# Uses the file '/tmp/printer' to determine
# which printer is connected
LOG=/tmp/filter.log
if [ ! -f /tmp/printer ]; then
echo "/tmp/printer file missing" |
Mail -s "printer problem" markp
exit 1
fi
PTYPE=`cat /tmp/printer`
#
# uncomment to turn on debug output
#DEBUG=1
if [ -n "$DEBUG" ]; then
set -x
exec > $LOG 2>&1
echo $*
fi
cat - > /tmp/prt.in
FTYPE="`file /tmp/prt.in`"
if [ -n "$DEBUG" ]; then
echo $FTYPE
fi
if [ -n "`echo $FTYPE | grep text`" ];
then # TEXT
echo "$PTYPE text job" >> $LOG
if [ $PTYPE = epson ]; then
# takes it straight
lpr -h -Praw /tmp/prt.in
elif [ $PTYPE = cdj550 ]; then
# needs CR+L
awk '{printf "%s\r\n",$0}' \
/tmp/prt.in | lpr -h -Praw
elif [ $PTYPE = ljet4 ]; then
awk '{printf "%s\r\n",$0}' \
/tmp/prt.in | lpr -h -P4mvraw
fi
elif [ -n "`echo $FTYPE | grep -i \
postscript`" ];
then # POSTSCRIPT
echo "$PTYPE postscript job" >> $LOG
if [ $PTYPE = ljet4 ]; then
lpr -P4mvraw
else # all others non-postscript
gs -sDEVICE=$PTYPE -q \
-sOutputFile=- \
/tmp/prt.in | lpr -h -Praw
fi
elif [ -n "`echo $FTYPE | grep TIFF`" ];
then # TIFF
echo "$PTYPE TIFF job" >> $LOG
if [ $PTYPE = ljet4 ]; then
tiff2ps -ap /tmp/prt.in | \
lpr -P4mvraw
else
tiff2ps -ap /tmp/prt.in | \
gs -sDEVICE=$PTYPE -q -OutputFile=- \
- | lpr -h -Praw
fi
fi
if [ -z "$DEBUG" ]; then
rm /tmp/prt.in
fi
Copyright © 1994 - 2018 Linux Journal. All rights reserved.