Printing to Samba share printer

Hi everyone.

This is one problem I'm stuck with and can't find any information to help. It just looks like nobody using FreeBSD connects to an SMB-shared printer, or else nobody has any problems doing so. Whenever the documentation speaks about such matters, it is always about sharing a locally connected printer via Samba, but never the other way around.

Now while LPD documentation just omits altogether the option to print to a Windows networked printer as some nonexistent solution, with CUPS it's supposed to be quite straightforward. Any Windows shared printer gets added using an URI like
Code:
smb://server/printer
.

Yeah, but the problem is my CUPS refuses to recognize the URI! !!!

After some research installed cups-samba, all to no avail. Installed also GNOME's system-config-printer -- still the same thing, no option to add a Windows network printer, the URI being supplied goes unrecognized.

Tried the thing through smbclient to check if the system can see the printer at all. No problem there. A simple testing command like echo -en "\r" | smbclient "//myhost/my_shared_printer" -c "print -" -N makes the printer work, so it is accessible to the system using installed Samba software. Also, since I'm talking about GNOME's support for SMB, I can confirm that I can see all my Windows network shares in Nautilus via Network. Just some link is missing somewhere.

Since I'm getting to love FreeBSD more and more (Linux is just getting too bad), I'm really concerned to find solutions to all such minor problems.

Just looks like this version of CUPS doesn't know about Samba. What can be done, I wonder? It is -RELEASE 9.1; GNOME, CUPS, cups-samba were all installed via pkg_add.
 
OK, installed additional packages: cups-smb-backend. It recognizes now smb:// URI type.

Then the message becames:
Code:
/usr/local/libexec/cups/filter/foomatic-rip not available
So I installed foomatic-filters.

Now it's:
Code:
Unable to connect to CIFS host, will retry in 60 seconds..
In the meantime I'm still having no problems printing to the printer via the smbclient command mentioned in the previous post.
 
Why thank you very much, I was actually looking for some way to use lpd, rather than CUPS.

Just wonder why the official documentation that's been around for years contains no examples on the similar setup... Is it because those willing to bother with FreeBSD usually have a printer of their own and seldom have to connect to Windows-attached printers?
Well I do have one at home, but in the office it isn't mine to command :). Besides, just for the sake of trying things out it is worth trying this way.

@DutchDaemon: Thank you for formatting my message and sorry for not doing it myself. Now I can see from your edit how to use those [file], [man] and [cmd] tags to make my posts more readable :).
 
Last edited by a moderator:
free-and-bsd said:
Why thank you very much, I was actually looking for some way to use lpd, rather than CUPS.

Just wonder why the official documentation that's been around for years contains no examples on the similar setup... Is it because those willing to bother with FreeBSD usually have a printer of their own and seldom have to connect to Windows-attached printers?
Well I do have one at home, but in the office it isn't mine to command :). Besides, just for the sake of trying things out it is worth trying this way.

The Handbook printing section is very old and could stand some updating. My article linked above covers the things I felt were important today, or most of them, anyway.

And it may just be that most office printers are on the network directly rather than shared through Windows. Certainly that's the way I always set them up, more reliable and open.
 
OK thanks for additional edit tips, this definitely looks better ;)

And yes, thanks for your article, I just read it. I will have to wait until I get back to the office. Never knew how Ghostscript can be used here, this is all VERY interesting.
 
free-and-bsd said:
OK thanks for additional edit tips, this definitely looks better ;)
You're welcome. If you have at least looked at the list of BB Code tags you will have noticed that there are quite a lot of them. It's rather unrealistic to expect new forum users to familiarise themselves with all of them right away (in fact, I think there are probably few non-staff users who know them all) but [CMD], [CODE] and [FILE] are the most important, which is why they are described separately here. If you start with learning when and how to use those three, that will already go a long way. The others will come as you spend more time here and moderators nudge you towards them, like we did just now.
 
I think cups-smb-backend has a problem working with system-config-printer GNOME package.

Here's the problem. When starting system-config-printer command the dialogue window offers a "Windows printer via SAMBA" under "Network Printer" all right. However, when smb://hostname is entered as offered, the SMB share never gets browseable using the "Browse..." button on the right -- as it normally should.

Meantime, the reason I couldn't make CUPS connect to the printer using web interface at http://localhost:631 was a Windows share name containing spaces (i.e. "Samsung ML-2950 Series"). With spaces removed from the actual share name, CUPS found the printer and it works fine now. It seems, the URI box in "Administration->Add printer" dialogue cannot parse spaces in share names (even if double quoted), so CUPS uses a corrupted share name and "cannot connect to CIFS...".

So we can mark this particular problem as "SOLVED".
Thanks to everyone for help.
 
...Talking about lpd filters, how does this all work?

The information is so scarce... how do I write a simple filter to accept the stream from lpr and feed it to, for example, smbclient "//VLAD/Samsung_ML-2950" -c "print -" -N?

Clearly, this isn't enough:
Code:
#!/bin/sh
smbclient "//VLAD/Samsung_ML-2950" -c "print -" -N
This doesn't work. Just have no idea how to make it read from the input it receives from lpr.
 
OK, /etc/printcap that finally works for printing to SMB share with lpr is the following:
Code:
lp|samsung|Samsung ML-2950 Samba printer:\
        [B]:lp=/dev/null:[/B]\
        [B]:if=/usr/local/libexec/samba-if:[/B]\
        :sd=/var/spool/output/lpd:\
        :lf=/var/log/lpd-errs:\
        :sh:mx#0:
After try and error and reading of manuals lp=/dev/null was borrowed from the Ghostscript virtual printer setup as a fitting entry for a setup without any local/remote device definition. The input filter /usr/local/libexec/samba-if is a modification of the one offered here by @wblock@:
Code:
#!/bin/sh
IFS="" read -r first_line
echo "$first_line" && cat && printf "\004" \
 | smbclient "//VLAD/Samsung_ML-2950" -c "print -" -N && exit 0
Only, something must be wrong, because it prints only empty pages ;).
Please, @wblock@, what is missing in my filter?
 
Last edited by a moderator:
Reading the first line of the file separately is not needed unless you plan to do something with it, so that can be simplified.

For testing, redirect the input to a file instead of smbclient and check the contents of that file. If that is okay, pipe that file into smbclient manually for a test. The Windows system may be trying to reinterpret the input instead of passing it directly to the printer. To fix that, the "Print Processor" has to be changed on the printer properties: http://www.microsoft.com/resources/...sag_printconcepts_cpu_datatypes.mspx?mfr=true.
 
But "first_line" is just a variable, isn't it?
When I cut the | smbclient ... part from the filter and do cat myfile.ps | /path/to/myfilter, it outputs all my PS file fed to stdout just as it is. Which means, the same is being fed to smblclient
in the actual filter, which stays unaltered.

When I redirect this output to a file (text.txt) and compare it with the original (mozilla.ps), I have:
Code:
diff mozilla.ps text.txt
3768a3769
> 
\ No newline at end of file
 
Yes, the first line of the input was read separately in the original filter so it could be used to identify the type of incoming file. PostScript files will always start with %!PS, at least well-formed ones. This new filter does not care about that, and can skip the extra complexity:
Code:
#!/bin/sh
cat && printf "\004" \
 | smbclient "//VLAD/Samsung_ML-2950" -c "print -" -N && exit 0
(Untested.)

Does the file print correctly when manually sent with smbclient?
cat text.txt | smbclient "//VLAD/Samsung_ML-2950" -c "print -"
 
BTW, in case one has admin access to the Windows machine where the printer is connected, things become a bit easier and printing via smbclient ... etc command becomes unnecessary.

One may just install "Print Services for Unix" on the Windows machine in question and configure one's LPD to forward its printing tasks to that machine, which will now be running the TCP/IP printer spool and accept tasks from LPD. What an unexpected favour, eh??

Anyway, /etc/printcap in that case must be very simple:
Code:
HP LaserJet 1200|lp:\
  :lp=:rm=computer:rp=printer:sh:sd=/var/spool/lpd:

Since I've used my complicated version to print via SMB, I never used this. But people say this works OK.
 
That works, but requires XP Pro. And I recall difficulties with it. I'd trust the FreeBSD side more. Don't know about the situation with later versions of Windows.
 
Absolutely agreed :D. Cases have been reported, when this DIDN'T work with some printer for no obvious reasons... Or, should I say, for one that's pretty obvious: it's MS Windows and NOT Unix, ha-ha.
 
Back
Top