11.9. Printing to a SMB (MicroSoft) Printer

Microsoft use the SMB (Simple Message Block) protocol to transfer files and print jobs to hosts and printers. SMB can be used over TCP/IP, NetBEUI, IPX, and other lower level network protocols.

Unfortunately, most printers do not provide detailed status or error reports when using the SMB protocol. There are a very large number of printers that have deficient SMB support that causes problems when used in a high traffic or high throughput environment.

It is highly recommended that this protocol not be used unless there is no alternative.

If you have a printer or a remote print spooler that supports SMB You can use the SAMBA smbclient program to send a print job to an SMB client. The following is a sample Shell Script script which you can use:

    #!/bin/sh -x
    # This script is an input filter for printing on a unix machine. It
    # uses the smbclient program to print the file to the specified smb-based
    # server and service.
    # The 'smb' printcap entry below shows how to configure LPRng
    # for printing
    #
    # smb:
    #  :lp=|/usr/local/samba/smbprint
    #  :sd=/var/spool/smb:
    #  :filter= ... filter ...
    #
    # The /var/spool/smb/.config file should contain:
    #   server="PC_SERVER"
    #   service="PR_SHARENAME"
    #   password="PASSWORD"
    #
    # Set PC_SERVER to the server, PR_SHARENAME to the printer,
    # and PASSWORD to the password for this service.
    #
    # E.g.
    #   server=PAULS_PC
    #   service=CJET_371
    #   password=""
    #
    #
    config_file=.config
    if [ -f $config_file ] ; then
        eval `/bin/cat $config_file`
    fi
    #
    # NOTE You may wish to add the line `echo translate'
    # if you want automatic
    # CR/LF translation when printing.
    (
    #   echo translate
        echo "print -"
        /bin/cat
    ) | /usr/local/bin/smbclient "\\\\$server\\$service" \
       "$password" -U "$server" -N -P 1>&2


If the above script was in /usr/local/libexec/filters/smbprint, the printcap entry for this printer would be:

    pauls_pc:
      :sd=/var/spool/lpd/%P
      # we filter the output
      :lp=|/usr/local/libexec/filters/smbprint
      # you can add filters if you want to do specific actions
      :ifhp=model=hp4
      :filter=/usr/local/libexec/filters/ifhp