Compartir un puerto USB mediante Samba

Imagen de Fernando.R
0 puntos

Estimados haces 15 días empecé a aprender Linux y me re copo.

La verdad si bien he tenido tropiezos no me parece difícil y una vez que lo aprenda bien intentare implementarlo a todo nivel en la empresa donde trabajo.

En este momento se me presento un problema que no pude resolver y se los dejo como reto:

Tengo la necesidad de compartir un puerto USB mediante Samba en mi Ubuntu (con el objetivo que desde otra PC con XP pueda acceder a cualquier dispositivo conectado a dicho puerto).

Se me ocurrió porque tengo una impresora que no tiene drivers para Linux (Canon MF3110) y me gustaría acceder a ella desde un XP estando dicha impresora conectada físicamente por USB a mi Ubuntu (sin embargo no es solo por mi impresora es para saber si se puede hacer, cosa de poder aplicar esto mismo a situaciones similares).

No quiero usar maquinas virtuales ni conectar la impresora a la PC con Windows.

El experimento consiste en que una vez que pueda compartir el puerto USB e instalar los drivers desde el XP, la comparto en dicho S.O. y la utilizaría mediante Samba desde el Ubuntu y Obviamente desde el XP.

Si alguien se le ocurre una idea le estaré muy agradecido.

P.D.: Si necesitan más datos avísenme.

Saludos y muchas gracias desde ya!!!

Fernando Reich

Imagen de Gabriel_M
+1
0
-1

Hola:

Samba te permite compartir impresoras, para ello debe configurarse con algo así como este ejemplo:

Impresoras en Samba.

Las impresoras se comparten de modo predeterminado, así que solo hay que realizar algunos ajustes. Si se desea que se pueda acceder hacia la impresora como usuario invitado sin clave de acceso, basta con añadir public = Yes en la sección de impresoras del siguiente modo:

[printers]
comment = El comentario que guste.
path = /var/spool/samba
printable = Yes
browseable = No
writable = no
printable = yes
public = Yes

Windows NT, 2000 y XP no tendrán problema alguno para acceder e imprimir hacia las impresoras, sin embargo Windows 95, 98 y ME suelen tener problemas para comunicarse con Samba para poder imprimir. Por tanto, si se quiere evitar problemas de conectividad con dichos sistemas operativos hay que agregar algunos parámetros que resolverán cualquier eventualidad:

[printers]
comment = Impresoras.
path = /var/spool/samba
printable = Yes
browseable = No
writable = no
printable = yes
public = Yes
print command = lpr -P %p -o raw %s -r
lpq command = lpstat -o %p
lprm command = cancel %p-%j

Se pude definir también a un usuario o bien un grupo (@grupo_que_sea) para la administración de las colas de las impresoras:

[printers]
comment = Impresoras.
path = /var/spool/samba
printable = Yes
browseable = No
writable = no
printable = yes
public = Yes
print command = lpr -P %p -o raw %s -r
lpq command = lpstat -o %p
lprm command = cancel %p-%j
printer admin = fulano, @opers_impresion

Con lo anterior se define que el usuario fulano y quien pertenezca al grupo opers_impresion podrán realizar tareas de administración en las impresoras.

Para que esto funcione, la impresora tiene que estar instalada con sus correspondientes drivers en cada operativo.

Lo que planteas, si no entendí mal, es que como no habría un puerto USB en la máquina Windows y no tienes drivers para Linux, en el puerto USB de Linux instalarías la impresora en Windows con sus drivers Windows.

Si compartes el puerto USB en la red, tal como harías con un cdrom, cdrw, hd, etc., tendría que funcionar, pero solo en Windows, pues Linux no tendría sus drivers para reconocerla, además tendrías que enceder la pc Linux un tiempo bastante importante antes que la máquina Windows, para poder acceder por la red a su puerto USB compartido.

Por lo tanto si ó si necesitas drivers que funcionen en Linux, y una vez obtenidos es más práctico que la instales en Linux y la compartas con Windows.

Visita esta página:

http://openprinting.org/show_printer.cgi?recnum=Canon-MF3110_3111

Aqui tienes en inglés un como hicieron funcionar tu impresora:

-----------------------------------------------------------------------------------

 


HOWTO - Print to a windows printer from linux WITHOUT needing any linux printer drivers/PPDs.

by Justin Yackoski - (my email address is my first name @ my last name dot name)

Translations

If you've translated this HOWTO into another language, please let me know so I can add it. I would be happy to host the translation here if you send me the HTML! If you have questions and are using a translated version, you'll either have to ask the author of the translation or another speaker of that language, or ask me the question in English. What is this HOWTO for?

People who have at least 1 windows PC, and 1 or more linux PCs connected via a network. This HOWTO assumes that the printer is connected to the windows PC, the windows PC is always on, and the printer is properly installed on the windows PC.

Why would you want to do this?

Without this method, your printer must be supported under linux to be able to print to it from linux, even if its attached to a windows PC and you want to print to it via SMB. So, in theory, as long as you have a windows PC on your network to connect your printer(s) to, you can print to ANY printer regardless of its support for linux. I've tested this setup with an HP LaserJet 5L (which is normally supported by linux), and a Canon imageCLASS MF3110 (which is NOT at all supported by linux as of this writing). Note that the only change needed to switch between printers is to change the default printer on the windows PC.

Windows PC Requirements/Assumptions

Linux PC Requirements/Assumptions

  • CUPS is installed and working properly
  • SAMBA client program (smbclient) is installed

Windows PC Setup Spool share

The windows PC is not going to actually share its printer via SMB. Instead, a directory will be shared, which will be used as the spool/dropbox directory.

First, create a user via the windows control panel. In this example, the username is "print" and the password is "print". You should use a better password.

Second, create a directory to share. In this example, I'm using c:\temp\spool and assuming your windows PC's name is windows_pc

Third, share the directory and give the print use you created in step 1 full control over it

Test that you can access the share from the linux PC via smbclient. I.e., run: smbclient //windows_pc/spool -U print and make sure you can put a file into that shared directory

Dirwatch script

Next we need the dirwatch.py script, available from here dirwatch.py. Save it somewhere, i.e., in c:\scripts\dirwatch.py. Make sure you rename it to dirwatch.py (I've named it dirwatch.txt so my web server doesn't try to execute it!) The dirwatch script is based on Tim Golden's great example available at http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html

Edit the dirwatch.py script and make the following changes:

  • Change the path_to_watch variable (near the top) to your spool directory. Be SURE to escape any \'s, i.e., c:\temp\spool should be "c:\\temp\\spool".
  • Change the cmd variable (near the botom) so that the path to gsprint.exe is correct. NOTE: even if your printer is black&white, you should still leave the -color option there unless you have problems. This option enables 24-bit greyscale, instead of 8-bit.

Run the dirwatch script by double-clicking on it. A window will open up that shows its output

Test the dirwatch script by using smbclient (as described above) to PUT and then RENAME a postscript file (with a .ps extension) into your spool share. If things are working properly, the .ps file will be printed out on your printer, and you should see output on the python terminal window on the windows PC

NOTE: The dirwatch script will only recognize files when they are RENAMED, so you must first creating a file in the directory you specified in the path_to_watch variable , and then rename it.

Now that the dirwatch script is working, kill the script that is running. Rename dirwatch.py to dirwatch.pyw. With a .pyw extension, no console window will open when its run.

Run the new dirwatch.pyw script and place a shortcut to it in your windows startup folder so it is run automatically at boot

NOTE: If you ever notice things are being printed out multiple times, it is likely that 2 or more copies of the dirwatch.pyw script are running. Go to the windows task manager and kill all but one of the pythonw.exe processes. This should fix the problem.

The Windows PC is now fully setup.

Linux PC Setup Distiller PPD

The Adobe distiller PPD must be installed where CUPS keeps its PPDs. The distiller PPD is named ADIST5.PPD and is in the zip file available at http://www.adobe.com/support/downloads/273e.htm

Extract ADIST5.PPD and put it in CUPS' PPD location. Generally, this is /usr/share/cups/model/. You should also rename it to lowercase, adist5.ppd.

winp script

Download the winp script from winp. Make it executable, and put it where CUPS keeps its backend scripts, usually /usr/lib/cups/backend/. The winp script is a modification of the pdfdistiller script by Michael Goffioul

Create a spool directory on your linux filesystem for the winp script to use. In this example, I use /var/spool/winp. Ensure that this directory is writable by the user that CUPS runs as, usually belonging to the group lp. Assuming CUPS runs as a user in the lp group, this can be accomplished by running chgrp lp /var/spool/winp and chmod g+w /var/spool/winp.

NOTE: This is a SEPARATE spool dir on the linux PC. Not the one the windows PC is sharing. This one is just some local temporary space to work in

Edit the winp script and make the following changes:

  • Change SPOOLDIR to point to your winp spool dir, i.e., /var/spool/winp
  • Change SMBUSER to be the username of the user you setup during the windows part of the setup, i.e., print
  • Change SMBPASS to be the password of the user you setup during the windows part of the setup, i.e., print

Restart CUPS so it recognizes the new winp backend script.

CUPS printer setup

Now, create a new CUPS printer that uses the winp backend and the adobe distiller, by executing the following as root: lpadmin -p windows_printer -E -v winp://windows_pc/spool -m adist5.ppd Note that adist5.ppd is case-sensitive, so we assume you renamed it to lowercase. windows_printer is the name for your new printer, and you should replace //windows_pc/spool with the name of your windows PC and the name you picked for the spool dir that the windows PC is sharing. Don't forget the winp: in the beginning.

Try printing to your new CUPS printer. Hopefully it will work!. If not, check the CUPS error log, usually in /var/log/cups/ (try turning up the log level in CUPS and restarting CUPS), or the winp log at /tmp/winp.log. One of these 2 places should help diagnose the problem.

Using adobe acrobat instead (optional!)

If you have trouble using gsprint, notice print quality problems, or find that printing uses up a lot of CPU/memory on your windows PC, try the instructions in this section.

I found that using ghostscript on the windows PC to do the printing results in slightly different quality. Sometimes the acrobat-based printouts had some very slight alignment problems, where the filled-in areas of an object were just slightly off from the outline (you have to look very close to notice). Other times, ghostscript was slightly better (again, you have to look closely). Additionally, to use acrobat, you have to first convert the file to a PDF, which adds some processing time (and more chances for things to get mucked around during the conversion). Finally, if you use acrobat, whenever someone prints to the windows printer, an acrobat window will appear on the taskbar. It'll be minimized, and goes away on its own, but it does grab the focus.

Speed/memory-wise, Acrobat clearly excels here. I'm not sure if its because of processing PDFs instead of bigger PS files, or what. If your windows PC is slow or has limited memory, the Acrobat option may be better for you.

At any rate, if you'd rather have the windows pc use acrobat instead of gsprint, grab the winp-pdf script here winp-pdf, and edit it the same way as described above under the winp script section. Also, edit the dirwatch.py script and uncomment the line with acrord32.exe in it, and commend out the one with gsprint.exe in it. Also, you'll need to get the gdputil.exe file and put it on your path someplace (i.e., in c:\winnt\system32) available from http://www.watchdirectory.net/watchDir/GdPUtil.html.

Limitations

  • If the windows PC is off and you try to print, the CUPS printer you setup will stop itself. You'll have to manually restart it when the windows PC is back on & ready via the CUPS admin interface.
  • I don't think there's not a whole lot of control from the linux PC over things like print quality, collating, etc.
  • The SMB user/pass are hard-coded into the winp script. It would be better if they were part of the URI used when you setup the printer via CUPS. You'll have to add that feature if you want multiple printers with different passwords.

Troubleshooting/Improvements Several people have written me with tips/suggestions on how to fix problems they've encountered. If you've fixed something or improved something that you think other people would benefit from knowing about, please email me and I'll add it here. Firewall Issues If you can't connect to the Samba server and can't figure out why, your firewall may be the problem. Note that you may have a firewall on BOTH your linux and windows computer by default, and you'll (possibly) have to modify them both! The SMB protocol needs ports 135 and 139 allowed for TCP, and 137 and 138 allowed for UDP. On your windows computer, you should add your linux PC as a trusted IP or network, and vice versa. Also make sure broadcasts are allowed. In linux, you need to set FW_TRUSTED_NETS and FW_ALLOW_FW_BROADCAST_EXT to accomplish these two things, see HowTo Firewall Linux and Windows Hosts in a SOHO LAN for more info. Note that I don't have firewalls on my computers because I'm behind a NAT, and my Windows XP PC (upgraded from 2000, so maybe the settings are non-default) didn't have any trouble with this, so I can't offer much more advice besides what I've already mentioned. Thanks to Andrew Stein for this information.

 

----------------------------------------------------------------------------------- 

Saludos y suerte

Gabriel

+1
0
-1
Imagen de Fernando.R
+1
0
-1

Gabriel, muchas gracias por responder.

Pero en realidad no me sirve esa solución ya que no puedo conectar directamente la imprsora a la PC con XP.

Por otro lado no me importa demasiado no poder imprimir desde mi Ubuntu.

Mi mayor precupación es imprimir desde la PC con XP con una impresora conectada por USB a una PC con Ubuntu.

¿Como harias para compartir el puerto USB?

Saludos y si me podes ayudar con esto te estare muy agradecido.

Fernando Reich

+1
0
-1
Imagen de Gabriel_M
+1
0
-1

Hola:

Yo intentaría:

Para compartir el dispositivo USB

Abrir el archivo /etc/samba/smb.conf para modificarlo :

sudo nano /etc/samba/smb.conf

y le agregaría, al final, algo como esto :

[USB]         
comment = USB Compartido
path = /media/USB0 (aqui el que corresponda a la impresora)
public = yes
writable = no
browseable = yes

Saludos y suerte. 

Gabriel

+1
0
-1
Imagen de Fernando.R
+1
0
-1

Gabi buenos días,

Lamento ser un re pesado pero no funciono esto ultimo porque en la carpeta "media" no hay ningun archivo o subcarpeta que empiece con USB

Habria que buscar alguna forma de agregar componentes del sistema a la carpeta "Media".

Voy a buscar en Internet a ver si encuentro algo.

Si se te ocurre algo pasame el dato.

Saludos y MUCHAS GRACIAS!!

Fernando 

+1
0
-1
Imagen de Fernando.R
+1
0
-1

Gabi me surgieron los siguientes problemas:

1) No se si usar mount o pmount (no se cual cual me conviene).

2) Tampoco se que Sistema de archivos usar ya que no es un pendrive si no un puerto USB comun.

Saludos!

Fernando 

 

+1
0
-1
Imagen de Gabriel_M
+1
0
-1

Hola Fernando:

Yo probaría montarlo directamente al inicio en fstab.

Primero crearía el directorio /media/usb0 (por ejemplo)

sudo mkdir /media/usb0

Luego le daria todos los permidos

sudo chmod -Rf 777 /media/usb0

Despues editaria /etc/fstab , para montarlo, con type auto y auto montaje

sudo nano /etc/fstab

Y le agregaría esta línea

# <file system> <mount point> <type> <options> <dump> <pass>

   /dev/usb0     /media/usb0      auto      rw,user,auto     0           1 

Y reiniciaría con la impresora conectada en usb0 y encendida. 

Espero te sirva.

Saludos y suerte. 

Gabriel

+1
0
-1
Imagen de Fernando.R
+1
0
-1

Gabi ya esta altura me da verguenza seguirte haciendo preguntas as (estoy abusando de tu buena voluntad).

Mira lo que no he logado es asociar:

Bus 005 Device 002: ID 04a9:2660 Canon, Inc.

Al  /media/usb0 y al /dev/usb0

No se como le digo a Ubuntu que el USB0 es el Bus 005 Device 002:...

También puede ser un problema que en "/dev" no hay ningun usb0 si no: "/dev/usbdev1.1_EP0", "/dev/usbdev1.1_EP81"  etc.

¿Que opinas?

Cuando aprenda Linux, voy a compartir mis conocimientos como vos!!

 Saludos y gracias

Fernando

+1
0
-1
Imagen de Gabriel_M
+1
0
-1

Hola:

Pues has dado las respuestas.

Monta o /dev/usbdev1.1_EP0

o /dev/usbdev1.1_EP81

en /media/USB0

La forma para saber cual es sería por ejemplo, en Ubuntu conectar un pendrive en el USB y ver cual es el montado si el EP0 o el EP81 para identificarlos.

Una idea: existen unos drivers propietarios para cannon en una página .de, que en linux te imprimen con un logo como marca de agua hasta que pagues por la licencia, como solo te interesa usar la impresora en windows, podrías instalarla en Ubuntu con esos drivers, ponerla como compartida con samba e instalarla en windows con sus drivers windows e imprimir sin problemas.

Editado---------------

Esta es la página de los drivers

http://www.turboprint.de/english.html

Fin edicion----------- 

Saludos y suerte.

Gabriel

+1
0
-1
Imagen de Fernando.R
+1
0
-1

Gabriel MUCHAS GRACIAS POR TU AYUDA!!!!!!!!!!! 

Funcione o no, tu me has mostrado porque Linux avanza en el mundo

 

Saludos

Fernando 

 

 

+1
0
-1