SysV interface script

Dave Horsfall dave at fgh.geac.com.au
Tue Sep 8 09:45:18 GMT 1998


A long time ago, on a mailing list far away, I promised to send the SysV
interface script that I use with success; the supplied one is a bit, err,
basic...

Well, one thing led to another, and I quite forgot, so without further
ado, here it is (usual disclaimers):

#!/bin/sh
#
# This interface script drives a PC-attached printer via the SAMBA utility.
#
# This script is a gross simplification of the "official" SysV interface
# script, whilst attempting to achieve much of the same functionality.
#
# Note the almost fanatical redirection of output; lpsched treats any
# output from this script as a problem with the request, and kills it,
# exit codes notwithstanding....
#
# In a previous life, it was distributed with the SAMBA software, but
# has since been hacked to the point of non-recognition.
#
# Dave Horsfall, FGH.
#

# clear out the unwanted parameters
copies=$4	# We want this one, but.
shift; shift; shift; shift; shift

pw=""		# We *must* supply a password

smbclient=/usr/local/samba/bin/smbclient
lptell=/var/spool/lp/bin/lp.tell	# Regrettably necessary
ping=/usr/sbin/ping

printer=`basename $0`

#
# Note the use of upper-case names.
#
case $printer in
prw1)
    server=wpark1
    server1=WPARK1	# SMB name
    service='PICKING'
    ;;
esac

#
# PCs have a distressing tendency to be switched off; let's spare
# ourselves some heartache.
#
$ping $server > /dev/null 2> /dev/null
if [ $? != 0 ]
then
    echo "The PC \"$server\", for \"$printer\", is not reachable." | $lptell $printer
    disable -r "$server not reachable" $printer > /dev/null 2>/dev/null
    exit 129	# Anything > 128 will keep the job
fi

#
# If smbclient is handed a bad service name, it exits without reading,
# thus SIGPIPEing us.
#
# What about a test for the service name?  Something like:
# smbclient -L $server | grep Printer | awk '{ print $1 }' -ne $service ??
#
i=1
while [ $i -le $copies ]
do
    (
	trap "exit 1" 13

	echo translate
	echo "print -"

	case "$printer" in
	An-HPLJ-printer)
	    echo '\033E\c'
	    ;;
	esac

	cat $*

	case "$printer" in
	HPLJ)
	    echo '\033E\c'
	    ;;
	esac

    ) | $smbclient "\\\\$server\\$service" $pw -N -P -U % > /dev/null 2> /dev/null
    i=`expr $i + 1`
done

exit=$?
if [ $exit -ne 0 ]
then
    #
    # Lpsched seems a little touchy about exit codes.
    #
    exit=129
    echo "Lost contact with $server" | $lptell $printer
    disable -r "Lost contact with $server" $printer > /dev/null 2> /dev/null
fi

exit $exit

-- 
Dave Horsfall VK2KFU  dave at geac.com.au  Ph: +61 2 9978-7493 Fx: +61 2 9978-7422
Geac Computers P/L (FGH Division) 2/57 Christie St, St Leonards 2065, Australia



More information about the samba mailing list