Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Featured

CUPS Printing to a File

Submitted by on September 17, 2014 – 7:17 pm

Using CUPS to print to a file instead of an actual printer is a great idea for troubleshooting and archiving purposes. This saves trees but, most importantly, saves you the walk to the printer. So, how does one go about setting this up? I am assuming you already have working CUPS server all setup and properly tested. Here’s what you need to do:

Shutdown cupsd via /etc/init.d on Linux and older Solaris versions or via “svcadm disable” on Solaris 10+.  Add the following new printer to /etc/cups/printers.conf as the very first printer, before any other <printer></printer> entry.

<Printer fileprint>
Info FilePrinter
DeviceURI fileprint.sh
State Idle
Accepting Yes
Jobsheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
</printer>

Create a directory that will store your printouts:
mkdir /var/cups_printouts ; chmod 777 /var/cups_printouts

Create this script: /usr/lib/cups/backend/fileprint.sh with the following content:
#!/bin/bash
cat $6 > /var/cups_printouts_`date +'%Y-%m-%d_%M%H%S'`.print

Make sure the script is executable by non-privileged users:
chmod 777 /usr/lib/cups/backend/fileprint.sh

In case you’re wondering what “$6” is, here’s a list of CUPS command-line arguments:
# $0 - name of the script
# $1 - job number
# $2 - user
# $3 - filename
# $4 - number of copies
# $5 - ?
# $6 - spooler file name

Start cupd and try printing something:
lp -d fileprint /etc/hosts

Check in /var/cups_printouts and, if everything went as expected, you should have a *.print file waiting for you there. Hopefully, this makes your life slightly easier.

Print Friendly, PDF & Email

Leave a Reply