Using System V interface scripts with CUPS printing
Author: TonyLawrence
Date: Tue Mar 15 12:00:16 2005
Subject: Using System V interface scripts with CUPS printing
Using System V interface scripts with CUPS printing
CUPS is a powerful and flexible printing system, but sometimes all we need is the simplest things. For example, very often for application printing, all I want is a raw queue. I just want cups to pass my data untouched to some device. That's easy enough with cups:
lpadmin -p myprinter -E -v parallel:/dev/lp
is all that is needed. The "-v" could also go to a network port or a serial port.
But what if I wanted to add an automatic form feed to the end of that, or do some other special processing? I'd have to get into cups ppd files, add a filter - a lot of work for something so simple.
It doesn't have to be. Cups can use System V interfaces scripts. We'll create a simple script that just adds a form feed:
#!/bin/bash
shift;shift;shift;shift;shift
cat $*
echo -e "\f\c"
Let's say we called that script "/tmp/myff". We add it to the raw printer like this:
lpadmin -p myprinter -E -i /tmp/myff -v parallel:/dev/lp
YOU CAN ONLY USE SYS V INTERFACES SCRIPTS WITH RAW PRINTERS. No PPD files will be used, no other filters will be processed. This script will be the ONLY thing your data passes through.
The /tmp/myff will be copied to /etc/cups/interfaces. If you now send a job:
date | lp -d myprinter
a form feeed will be added.
By the way, that #!/bin/bash isn't optional here. Cups uses execve to run the script, so it needs a binary file or an interpreter line like that.
I threw away everything else here, but the variables passed to the script are the job number, the user, the source of the data (stdin), the number of copies, and finally the actual data file. So for the invocation above, the five variables I shifted away might have been
17 root (stdin) 1 /var/spool/cups/d00017-001
Obviously, there's much more that you can do at this level - emailing, data transformation, whatever you need. However, for complicated tasks, the cups filtering system does have advantages, so this method should be reserved for the simple cases.
See also foomatic,magicfilter
CUPS print to file - the hard way!
What are printer interface scripts?
Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)
| Views for this page |
| Today | This Week | This Month | This Year | Overall |
| 2 | 2 | 240 | 2,044 | 15,065 |
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site:
Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Publishing your articles here
Sun Oct 16 23:26:15 2005: Subject: bruceg2005
When you add /tmp/myff, this is at the creation of the printer. Is it possible to add a filter to an existing printer?
- Bruce
Mon Oct 17 09:18:30 2005: Subject: TonyLawrence
Not likle this, no. SysV filters are all or nothing. A "backend" filter is a little more complicated, but can be added to any printer (well, not a SysV style, but any ordinary cups printer).
But as I said in various places here, cups is complicated. Sometimes that's good, but it has a steep learning curve.
Mon Oct 17 13:51:39 2005: Subject: bruceg2004
I purchased the ESP Print Pro version (by the writers of CUPS) - http://www.easysw.com - and they have some good bulletin boards for asking questions. I have already made some suggestions, which the author will incorporate into PrintPro 5.
The one thing I like about the "Pro" version of CUPS, other than the support system, is the graphical front end to 'lp', called 'glp'. This gives you more of a "Windows" type of print dialog for your jobs, which is greatly needed. Although KDE has a very nice interface, this is even more complete.
I will ask the support system what the easiest way to do what I am asking is, and post back here. The author is the one who answers the majority of support questions, which is nice. Usually, within 24 hours.
- Bruce
Mon Jul 2 17:35:21 2007: Subject: TonyLawrence
I just had someone unable to do this - problem was the same as described at http://aplawrence.com/Bofcusm/1613.html
Don't use Windows to write your scripts!!!
Add your comments