APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Using System V interface scripts with CUPS printing

© December 2009 Anthony Lawrence

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. You might want to do that if your printer will handle both simple text that you need to mess with, but let's take the simple, text only case first.

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:

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 feed 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.

You CAN do both - that is, let Cups handle the stuff it wants to handle and have your script handle straight text. It's a bit more work, but the scripts themselves do not change,

To accomplish this, I created "/etc/cups/myfilters". Cups is security conscious (as it should be!) so make sure that directory has the same owner and group and perms as /etc/cups/ppd. Put your script in there, and again make ownership and perms match (-rwxr-xr-x 1 root _lp on my OS X machine).

You then need to modify the ppd file for the printer. In my case, that was "/etc/cups/ppd/hplaser" and I added a new "Filter" line:

*cupsFilter: "application/vnd.cups-raster 50 rastertohp"
*cupsFilter: "text/plain 0 /etc/cups/myfilters/TextToPrinter"

The first line was already there; I added the second.

Without that new line, text such as "date | lp -dhplaser" would have been handled by Cups. With this, text jobs go through my filter. This doesn't affect things like printing a web page from a browser or printing from TextEdit, but it will grab things like that command "date | lp -dhplaser".

You'll need to do a "killall -HUP cupsd" (OS X, Linux) or otherwise restart Cups when you initiate these changes; if you need to modify the filter later you can dispense with that and just go ahead and edit it.

In documentation for shell script filters you will see code like this:

[ -n "$6" ] && exec <"$6"
cat -

That's because filters can be chained together - the first filter gets passed the file to print in $6 and all others (except the last) are expected to read from stdin and write to stdout. The last filter is the "back-end" which writes to the actual printer hardware (or network port).

See Using Your Own Filters to Print with CUPS for a chaining example.

See also foomatic,magicfilter CUPS print to file - the hard way! What are printer interface scripts?

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Using System V interface scripts with CUPS printing


Inexpensive and informative Apple related e-books:

Take control of Apple TV, Second Edition

Are Your Bits Flipped?

iOS 10: A Take Control Crash Course

Photos for Mac: A Take Control Crash Course

iOS 8: A Take Control Crash Course

More Articles by © Anthony Lawrence

Related Articles

Sun Oct 16 23:26:15 2005: 1209   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: 1211   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: 1213   bruceg2004

I purchased the ESP Print Pro version (by the writers of CUPS) - (link) - 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: 3051   TonyLawrence

I just had someone unable to do this - problem was the same as described at (link)

Don't use Windows to write your scripts!!!

Fri Aug 14 23:45:25 2009: 6751   Marcelo

Hi there... I got the inverse problem you'd described in your example.

I receive print jobs from a mainframe via LPD. And it worked pretty well in my old Conectiva 8.0 (Brazilian Distro). But it crashes... then I'm trying Ubuntu 9.04 (yes I know it's pretty fresh).

The problem is that cups-lpd, the work-around for cups listen on port 515 an receive LPD jobs, adds a #$#$#$&% form feed at every job.

The epson FX-890, responsible to the hard work is printing a blank page at each job, thus wasting a lot of paper.

I'm scrutinizing the Internet to fix that, and I refuse to go back to Conectiva 8.0 - it's a honor matter :-) !

So I've found your page...

May I do a script to remove that form feed?
Any ideas?

Thanks in advance,


Sat Aug 15 02:18:05 2009: 6752   TonyLawrence

That's in the printcap file.

Add ":sf:" to suppress formfeed.

Sat Aug 15 14:05:29 2009: 6754   Marcelo

Yes I know "sf" do the magic, the problem is, at least in Ubuntu 9.04, that the /var/run/cups/printcap is written by cups itself, and any changes you make on it are lost. The /etc/printcap is of no use, all CUPS uses is the /etc/cups/ppd/myprinter.ppd.


Sat Aug 15 14:12:05 2009: 6755   Mabafu




Tks anyway for your attention!



Tue Dec 22 15:17:53 2009: 7798   fsendinozaragozaes


We've migrated from an Unixware system to a Linux Box runing cups, we are using system v interfaces (through cups) to print to windows clients with a ftp server running.
Printing works just fine with normal files, but when printing a file with escape characters nothing happens. We've set cupsd to debug2 and when you issue an lp -dPRINTER we can see it start the job, but it doesn't call the inerface program and then cancels the job

PD : old time reader, good work

Tue Dec 22 21:58:36 2009: 7804   TonyLawrence


I suspect you aren't using the "raw" model (or pass "-o raw")

Wed Dec 23 02:13:53 2009: 7805   TonyLawrence


Sorry - you said Sys V - I missed that.

Your script has to have a shebang line - does it?

Wed Dec 23 02:28:45 2009: 7806   TonyLawrence


No - that can't be it either. Sorry - I'm tired. I'll look at it tomorrow.

Wed Dec 23 14:28:31 2009: 7808   TonyLawrence


I'm awake now :-)

This really sounds to me like the Sysv interface isn't being seen and that you are not using a raw interface. Can you verify with "ls -lut" that the interface IS being hit when you print?

Wed Dec 23 15:46:17 2009: 7809   TonyLawrence


The reason I say that is that if you don't use "raw" with normal cups, you can't send non-text through..

Fri Jun 1 01:02:41 2012: 11045   Khushal


Very useful. Thanks

Thu Sep 27 20:31:22 2012: 11346   ScottM


Hi Tony,

I'm running Ubuntu 10.04.4 and am trying to get an interface script working but lpstat tells me the script failed.

created the printer with

lpadmin -p file -E -i /tmp/file -v file:/dev/null

I've simplified my script to this but still won't work

echo $6 > /tmp/test

also tried

even left the script blank and lpstat still says
/etc/cups/interfaces/file failed

incidently while trying to figure this out read your other article about printing to file with CUPS and found that

lpadmin -p file -E -v file:/tmp/test

works. I had to temporarily put FileDevice On in cupss.conf while creating the printer.

I've tried setting permission to 777 on the script but didn't work. Cups did complain that the script was vulnerable when I restarted though.

Any suggestions would be appreciated.


Thu Sep 27 20:43:55 2012: 11347   TonyLawrence


No chance you wrote the file in Windows (see above)?

Fri Sep 28 13:52:59 2012: 11348   ScottM


No I used vim on the ubuntu server.

Fri Sep 28 14:00:04 2012: 11349   TonyLawrence


Well, I'm not sure why, but I'd start with the simple case of adding a line to the output.

Define a real printer like
lpadmin -p myprinter -E -i /tmp/myscript -v parallel:/dev/lp

And have myscript just echo something.. does it get to the printer?

Fri Sep 28 16:11:12 2012: 11350   ScottM


Ok, created printer as follows

lpadmin -p test -E -v socket://

date | lp -d test prints fine

created printer like this

lpadmin -p test -E -i /tmp/myscrip -v socket://

myscript is as follows


echo hello world

permissions in /etc/cups/interfaces
-rwxr-xr-x 1 root root 31 2012-09-28 11:58 test
also tried
-rwxr-xr-x 1 root lp 31 2012-09-28 11:58 test

lpstat gives ...

printer test now printing test-0. enabled since Fri 28 Sep 2012 11:58:17 AM EDT
Connected to printer...
test-27 root 1024 Fri 28 Sep 2012 11:58:17 AM EDT


printer test is idle. enabled since Fri 28 Sep 2012 11:58:22 AM EDT
Ready to print.
test-27 root 1024 Fri 28 Sep 2012 11:58:17 AM EDT

but nothing prints.

lpstat did give the /etc/cups/interfaces/test failed at on point also.

Thanks again for your time, I'm at my wits end.

Sat Sep 29 09:48:35 2012: 11351   TonyLawrence


I wonder if something has changed in CUPS since I wrote this..

I just checked a Ubuntu 11.04 LTS.

I did have to create /etc/cups/interefaces and chmod 700 it, but other than that, it worked immediately.

Sat Sep 29 10:17:27 2012: 11352   TonyLawrence


Oh, this is odd.

First attempt worked. Since then, it throws an error..

I'll dig in to it..

Sat Sep 29 11:13:07 2012: 11353   TonyLawrence


OK, this is interesting.

If I "sudo su -" and then print, it does NOT error.

But it never prints, either..

Mon Oct 1 14:36:52 2012: 11359   ScottM


Glad to hear that you're still looking into this. Hopefully you can figure this out.

Mon Oct 1 14:48:21 2012: 11360   TonyLawrence


Honestly, I'm baffled - something has changed in CUPS.

Mon Nov 5 08:40:52 2012: 11415   anonymous


As this page helped me, I thought it only fair to help back... I was trying to get an interface script working on Ubuntu, and after many hours of banging heads on desks I found that apparmor was interfering and stopping CUPS running the script; I checked it with dmesg and saw messages to that end.

I know nothing about apparmor, so disabled it for CUPS, and since then the script is working like a charm.

Hope that helps anyone.

Mon Nov 5 18:12:56 2012: 11416   TonyLawrence


Thanks! I had seen that somewhere recently.

Wed Nov 20 14:25:24 2013: 12368   shera


i am trying to set up cups to receive from a mainframe on port 515 and keep getting encryption error in the error_log. i have set cupsd.conf to DefaultEncryption Never. but still get same error. any suggestions?

Wed Nov 20 14:36:58 2013: 12369   TonyLawrence


No idea, sorry

Fri Nov 22 16:27:44 2013: 12371   RickHoyle


I'm working on CentOS 6.4 (64-bit) systems and cannot get CUPS to use the /etc/cups/interfaces/{printer_name} script. I've enabled debug for cupsd and checked logs for clues. I'm a pretty resourceful SCO-UNIX/CentOS guy, but this is kicking my butt. Taking a hint from an earlier post regarding 'apparmor', I've tried disabling 'selinux' to no avail. Anybody having similar issues?


Printer Friendly Version

Related Articles

Have you tried Searching this site?

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.

Contact us

Printer Friendly Version

One in a million is next Tuesday. (Gordon Letwin)

Linux posts

Troubleshooting posts

This post tagged:




Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode