New smbprint.sysv

Kevin Pendleton kevin at electron-pc.com
Thu May 9 13:36:03 GMT 2002


Hello all,

In order to follow the open source way, I have included a new version of 
smbprint.sysv that I wrote for printing from UNIX to NT.  I wrote it 
since the original script was very simple and had no built in features. 
 This script, written in perl, uses PCL commands (common to HP printers 
and possibly others) to change some of the possible options a printer 
driver would give you.  The script acts as a printer interface and print 
filter in UNIX and takes the -o option available to UNIX users when 
using the lp command.  I'm not sure what other printers use PCL commands 
because we only use HP here, but feel free to test it out in other 
configurations.  The options and setup are all documented in the script. 
Many of the PCL lines are escape characters and may not appear in all 
text editors.  I decided to call it smbprint.sysv.pcl to seperate it 
from the past and hopefully future versions.  Maybe someone could look 
into getting it to print postscript?  Anyway, here it is....

Kevin Pendleton
kevin at electron-pc.com
-------------- next part --------------
#! /usr/bin/perl

############################################################################
# A new version of smbprint.sysv for Samba printing from UNIX to NT
#   based off of smbprint.sysv version 1.0 - 13 January 1995
#   by Ross Wakelin <r.wakelin at march.co.uk> which was a modification of
#   the original smbprint (bsd) script
#
# 	Created by Kevin Pendleton - April 29, 2002
#                     (kevin at electron-pc.com)
#
# This script is a mix of a printer interface script and a print filter.
# This uses PCL commands to specify certain options for your print job
# by using  the -o parameter on the command line
#
#        lp -d printer -o option1,option2 filename
#
# No options are required.  If the option is not specified it will default
# to the printer's default settings.
#   Possible options:
#	* small (16.67 CPI), medium (12 CPI), or large (10 CPI)
#	* portrait or landscape
#		* portrait66 or landscape66 for 66 lines per page
#	* legal or letter
#	* manual or tray
#
# This script uses the smbclient program to print through Samba to the
# specified server and service.  To add this to your lp system, copy this
# file to your Samba directory (/usr/local/samba/lib), modify the server,
# service, user and password variables and then execute the following
# command (as root):
#
#   lpadmin -pprintername -v/dev/null -i/usr/local/samba/lib/smbprint
#
# where printername is the name that the printer will be known as on your
# UNIX box.  This script is copied into your printer administration directory
# (/usr/lib/lp or /etc/lp) as a new interface (interface/printername) so if
# you change the script, remove the printer and then add it again.  After
# adding the printer you must enable and accept the printer (as root)
#
#	enable printername
#	accept printername
#
# Don't forget to set up the Windows box to share the printer with the
# username and password that you specify below.
#
# The characters ^[ is a literal escape character. To create
# this character in vi hit cntrl-v then esc
#       !!!!!YOU CAN NOT JUST CUT AND PASTE IT!!!!!!
# **** Not that you would be messing with that, right? ****
############################################################################

# Change these values to your specific situation
# It's usually best to have the server and service in all caps
$server = "SERVER";
# Usually the service needs to be just one word
$service = "SHARENAME";
$log = "/tmp/$server.log";
$olog = "/tmp/$server.old";
$tmpfile = "/tmp/printfile";
$user = "username";
$password = "password";

############################################################################
# Don't change anything below here, except to remove CR/LF translation
# $new="print -\n";
$new="translate\nprint -\n";

# Rotate the logs
system("cp /dev/null $tmpfile");
system("mv $log $olog");

@val=@ARGV;

# Check for -o parameters
# First strip out flist info to prevent filenames from
# becoming options on accident.  You don't want a file
# named small to print small...
$params = $val[4];
$params =~ s/flist=\'(.*?)\s\'//;

# Check for paper size option
if ($params =~ /letter/){ $size = "2a"; }
elsif ($params =~ /legal/){ $size = "3a"; }

# Then check for paper source option
if ($params =~ /manual/){ $source = "2h" }
elsif ($params =~ /tray/){ $source = "4h" }

# Then check for paper orientation and VMI
# (Vertical Motion Index - lines per page)
if ($params =~ /landscape66/){ $orient = "1o5.45c" }
elsif ($params =~ /landscape/){ $orient = "1o" }
elsif ($params =~ /portrait66/){ $orient = "0o7.27c" }
elsif ($params =~ /portrait/){ $orient = "0o" }

# Finally check for font to use
if ($params =~ /small/){ $font = "(s0p16.67h0T"; }
elsif ($params =~ /medium/){ $font = "(s0p12h3T"; }
elsif ($params =~ /large/){ $font = "(s0p10h3T"; }

if ($size || $source || $orient) {
	$header = "&l";
	if ($size){ $header .= $size; }
	if ($source){ $header .= $source; }
	if ($orient){ $header .= $orient; }
	# Change the last letter to a capital
	$last= substr($header, -1, 1);
	$last = "\U$last";
	$header = substr($header, 0, -1) . $last;
}
if ($font){ $header .= $font; }

# add the header and footer with the file in the middle for each file
$index = 5;
while ($val[$index]){
	$new .= $header;
	$new .= `cat $val[$index]`;
	$new .= "E\n";
	open (PRINTFILE, "> $tmpfile");
	print PRINTFILE $new;
	close (PRINTFILE);
	$index++;
}

# Now send file(s) to the printer through Samba
$rc = `cat $tmpfile | /usr/local/samba/bin/smbclient \"\\\\\\$server\\$service\" $password -N -P -U$user >> $log`;

exit $rc;


More information about the samba-technical mailing list