1#!/bin/sh 2 3# This script is an input filter for printcap printing on a unix machine. It 4# uses the smbclient program to print the file to the specified smb-based 5# server and service. 6# For example you could have a printcap entry like this 7# 8# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint 9# 10# which would create a unix printer called "smb" that will print via this 11# script. You will need to create the spool directory /usr/spool/smb with 12# appropriate permissions and ownerships for your system. 13 14# Set these to the server and service you wish to print to 15# In this example I have a WfWg PC called "lapland" that has a printer 16# exported called "printer" with no password. 17 18# 19# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton) 20# so that the server, service, and password can be read from 21# a /var/spool/lpd/PRINTNAME/.config file. 22# 23# In order for this to work the /etc/printcap entry must include an 24# accounting file (af=...): 25# 26# cdcolour:\ 27# :cm=CD IBM Colorjet on 6th:\ 28# :sd=/var/spool/lpd/cdcolour:\ 29# :af=/var/spool/lpd/cdcolour/acct:\ 30# :if=/usr/local/etc/smbprint:\ 31# :mx=0:\ 32# :lp=/dev/null: 33# 34# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: 35# server=PC_SERVER 36# service=PR_SHARENAME 37# password="password" 38# 39# E.g. 40# server=PAULS_PC 41# service=CJET_371 42# password="" 43 44# 45# Debugging log file, change to /dev/null if you like. 46# 47# logfile=/tmp/smb-print.log 48logfile=/dev/null 49 50 51# 52# The last parameter to the filter is the accounting file name. 53# Extract the directory name from the file name. 54# Concat this with /.config to get the config file. 55# 56eval acct_file=\${$#} 57spool_dir=`dirname $acct_file` 58config_file=$spool_dir/.config 59 60# Should read the following variables set in the config file: 61# server 62# service 63# password 64eval `cat $config_file` 65 66# 67# Some debugging help, change the >> to > if you want to same space. 68# 69echo "server $server, service $service" >> $logfile 70 71( 72# NOTE You may wish to add the line `echo translate' if you want automatic 73# CR/LF translation when printing. 74# echo translate 75 echo "print -" 76 cat 77) | /usr/bin/smbclient "//$server/$service" $password -U $server -N >> $logfile 78