⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network-samba-print2win.html

📁 学习linux的工具书
💻 HTML
字号:
<HTML>
<HEAD>
<TITLE>Print2Win, print2win, Printing from linux to windows</TITLE></HEAD>
<BODY BGCOLOR="#000000" TEXT="#FFFF00" LINK="#FF8000" VLINK="#FF8040">
<h1>
Printing from Linux to a Windows 95/NT shared printer.
</h1>
<h2>
<render tag="center" style="TT">
or &quot;one less reason to have to use windoze on your desktop&quot;
<p>

</h2>
My setup :
<br>
	Slackware Distribution 3.2
<br>
	Kernel 2.0.33
<br>
	Samba 1.9.17p4
<br>
	LPRng 3.2.3
<p>
I have setup my system so that it can print in both text and postscript mode to an HP LaserJet 4.
<p>
<h3>
Step 1. Edit your /etc/printcap file
</h3>
My printcap file contains the following two printer definitions
<p>
<pre>
#start of printcap

hp4:\
        :lp=/dev/hp4:\
        :sd=/var/spool/lpd/hp:\
        :af=/var/spool/lpd/hp/acct:\
        :mx#0:\
  
     :if=/usr/local/print/texthp4:

ps4:\
        :lp=/dev/ps4:\
        :sd=/var/spool/lpd/ps:\
        :af=/var/spool/lpd/ps/acct:\
     
  :mx#0:\
        :if=/usr/local/print/pshp4:

#end of printcap

</pre>

<br>
<h3>
Step 2. Create your devices
</h3>
To prevent possible 'exclusive' open conflicts I have specified different devices in the :lp statement. Create these devices now.
<p>
<pre>
	bash# touch /dev/hp4
	bash# touch /dev/ps4
	bash# chmod 777 /dev/hp4
	bash# chmod 777 /dev/ps4

</pre>

<br>
<h3>
Step 3. Prepare LPD
</h3>
A common cause of printer problems is not to do with the setup of the files, but the setup of the directories used to spool and control the print devices.
<p>
<pre>
bash# mkdir /var/spool/lpd/hp
bash# mkdir /var/spool/lpd/ps
bash# checkpc -f


</pre>
After running checkpc, create anything that it has trouble finding, usually it is log and lock files.
<br>
When setting up a new system I always forget to create the /var/spool/lpd/lpd.lock.??? file.
<p>
<h3>
Step 4. Create those print scripts
</h3>
The printcap file specified an input filter for each device setup. These can be made quite complex (as in the example I used to get going) but I have created *very* simple ones that just do the print filtering. I have also created a /usr/local/print directory to keep them in, so
put them where you like, just make sure that printcap specifies their location.
<p>
The plain text filter :
<p>
<pre>
#!/bin/sh -x
#
# /usr/local/print/texthp4
#
# Plain text printing to an HP laserjet 4
#
logfile=/tmp/smb-print.log
(
        echo translate
        echo &quot;print -&quot;
        cat
        echo -e &quot;\f&quot;
) | /usr/local/samba/bin/smbclient &quot;\\\\OBSLON2\\mktghp4&quot; password -U username -N -P &gt;&gt;$logfile
#end of texthp4

</pre>

<br>
The postscript filter :
<p>
<pre>
#!/bin/sh -x
#
# /usr/local/print/pshp4
#
# Postscript printing to an HP Laserjet 4
#
logfile=/tmp/smb-print.log
(
        echo &quot;print -&quot;
        /usr/bin/gs -dSAFER -dNOPAUSE -sPAPERSIZE=a4 -q -sDEVICE=ljet4 -sOutputFile=- -
        printf &quot;\014&quot;
) | /usr/local/samba/bin/smbclient &quot;\\\\OBSLON2\\mktghp4&quot; password -U username -N -P &gt;&gt;$logfile
#end of pshp4

</pre>

<br>
Note: these filters expect to find the samba binary <b>
smbclient
</b>
 in the <b>
/usr/local/samba/bin
</b>
 directory. If you have installed samba elsewhere, change the smbclient line accordingly.
<br>
In these examples I am communicating with an NT server called <b>
OBSLON2
</b>
 which has a print service <b>
mktghp4
</b>
. (the many many '\' characters are required).
<p>
<h3>
Step 5. TCP/IP bits and bobs
</h3>
Naturally you require TCP/IP running on your system, and you need to inform samba of the IP address of the NT server. You should also ensure that the router can route stuff to the printer.
<p>
Ensure that you have an entry for the NT server in your <b>
/etc/hosts
</b>
 file. Mine looks like this :
<p>
<pre>
#
# hosts         This file describes a number of hostname-to-address
#               mappings for the TCP/IP subsystem.  It is mostly
#               used at boot time, when no name servers are running.
#               On small systems, this file can be used instead of a
#               &quot;named&quot; name server.  Just add the names, addresses
#      
        and any aliases to this file...
#
# By the way, Arnt Gulbrandsen &lt;agulbra@nvg.unit.no&gt; says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

#
For loopbacking.
127.0.0.1       localhost
1.0.12.17       lynx.obs lynx (my linux box)
1.0.21.125      OBSLON2
# End of hosts.

</pre>

<br>
Once this has been done, ensure that you have a route to the NT server by adding a route command to your <b>
/etc/rc.d/rc.inet1
</b>
 file.
<p>
<pre>
/sbin/route add -net 1.0.21.0 netmask 255.255.255.0 eth0

</pre>

<br>
Test the connection to the NT server using the nmblookup command :
<p>
<pre>
bash#  /usr/local/samba/bin/nmblookup -B 1.0.21.125 OBSLON2

</pre>

<br>
Which should return
<br>
<pre>
1.0.21.125 OBSLON2
</pre>

<br>
if successful.
<p>
<h3>
Step 6. Start LPD
</h3>
Start or restart LPD. If LPD is running then kill it and restart it (yes, okay, so you can probably also use lpc to do it nicely).
<p>
<pre>
bash# lpd
</pre>

<p>
If it is already running then,
<p>
<pre>
bash# lpd
lpd: Fatal error - Another print spooler is using TCP printer port, possibly lpd process '4788'
bash# kill -9 4788
bash# lpd

</pre>

<br>
<h3>
Step 7. Give it a go
</h3>
To test out the plain text print :
<p>
<pre>
bash# lpr -Php4 /usr/local/print/texthp4
</pre>

<p>
And wait to see what (if anything) appears
<p>
To test out the postscript mode, well use something that generates postscript (netscape for example, or ez-andrew) and print to queue ps4.
<p>
If you do not have some output generated, well, either your printer is offline, your printer daemon has a
problem, or I was *very* lucky to get mine working in the first place.
<p>

<HR>
<P><A HREF="mailto:webmaster@grawlfang.demon.co.uk">Mark W J Redding</A>, 2nd March 1998</P>
<P><A HREF="./linux.html">Return to the main Linux page</A></P></BODY></HTML>
<P><A HREF="../index.html">Return to the Index page</A></P></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -