printing
Olivier Nicole
on at cs.ait.ac.th
Tue May 31 19:11:14 PDT 2005
> > > how can i print a document in a windows shared
> >
> > I do that using samba, only samba client is needed.
> >
> > Olivier
> >
> can you explaime how?
0) I installed samba from the ports /usr/ports/net/samba
1) I have a shared printer on my windows machine, the printer share is
named APPLE, as I use win2k, the printer is accessible to the user
"printer", the win2k machine name is "olivier". I set-up a password
to protect my win2k printer.
For win98, it would be the same, but there is not user.
2) I create an entry in /etc/printcap, the entry is like:
# printers attached to users machine (Windows)
on-printer:\
:sd=/var/spool/on-printer:\
:mx=0:rs:sh:\
:lp=/dev/null:\
:if=/usr/spool/smb-printer:
3) I create the directory /var/spool/on-printer
4) I create the configuration file /var/spool/on-printer/.config that
contains (please put the password as defined in 1):
server = olivier
service = APPLE
password = *******
user = printer
domain = olivier
Note that server and domain are the same!
5) I installed the script /usr/spool/smb-printer. This script works
for win98 and win2k. It does a little bit of file coding, changing
CR into CRLF for the files that are not PostScript or PCL.
#!/usr/bin/perl
require "flush.pl";
## $logfile="smb-print.log";
## # or $logfile=/dev/null;
$logfile="/dev/null";
##
## open LOG, ">>$logfile";
## print LOG `/bin/ls -a`;
## for ($i=0; $i<=$#ARGV; $i++) {
## print LOG "$ARGV[$i]\n";
## }
$loggererr="/usr/bin/logger -i -t print_quota -p lpr.err";
$loggerinfo="/usr/bin/logger -i -t print_quota -p lpr.info";
$mess="SMB print job: -wd ".`pwd`;
for ($i=0; $i<=$#ARGV; $i++) {
$mess.="$ARGV[$i] ";
}
# read the config file
# the config file should consist of:
#
# server=servername
# service=printername
# password=something (be omitted if empty)
#
open IN, ".config";
$password="";
while (<IN>) {
chop;
s/\s*//g;
@t=split /=/;
$ar{$t[0]}=$t[1];
}
close IN;
#print LOG `ps auwx|grep perl`;
# read standard input and try to guess if we have a PCL or PostScript file
# or just plain text
# in case of plain text, we should translate CR-> CR/LF
# and add a ctrl-l at the end
#
open IN, "-";
$l=<IN>;
$t=0;
$t=1 unless $l=~/^(\\%.*\@PJL)|(%!PS)/;
$l=~s/([^\r])?\n/$1\r\n/g if $t;
#print LOG "$t\n";
$command="|/usr/local/bin/smbclient \"//$ar{'server'}/$ar{'service'}\" ";
if (exists $ar{user}) {
# we are in Win NT world
$command.="-U \"$ar{'user'}\%$ar{'password'}\" -W \"$ar{'domain'}\"";
}
else {
# we are in win 9x world
$command.="\"$ar{'password'}\"";
}
$command.=" -N >>$logfile";
#$command.=" -N -P >>$logfile";
# hide the user and password for the LOG
$obf=$command;
$obf=~s/[\w]+%[\w]+/****%****/;
$mess.="$obf";
open SMB, "$command";
print SMB "print -\n";
print SMB $l;
while (<IN>) {
s/([^\r])?\n/$1\r\n/g if $t;
print SMB $_;
$last=$_;
}
print SMB "" if $t && $last!~/\r\n$/;
close IN;
flush(SMB);
close SMB;
system "$loggerinfo \'$mess\'";
More information about the freebsd-questions
mailing list