These scripts are not for everyone. This is mainly an archive of how I managed several printing issues that I was faced with in my job. I'll summarize the scripts here and provide links to download them as well as I'll attempt to provide a "use case" or reason for it's existence.

All of these scripts are designed to run as root and are to be located in the same folder. In my system I used /root/printersync.

createprinters.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=5external link
This script was my first effort. I was tasked with creating a means of taking a printer list from an excel spreadsheet and using it to create printers in a new server. This seemed like a silly effort at the time since how was I going to identify which PPD file (printer driver file) was going to be used to create the new printer? This is especially difficult since the files are not named the same thing as the Name which appears in the CUPS administration web-page and the files that contains the PPD files are often left compressed as a *.ppd.gz file. You can usually find the printer PPD files located in sub directories of /usr/share/cups/model. In my system there are 6392 PPD files and most of them are compressed.

My first effort was a labor of love attempting to add the printer through the CUPS administration web-page discovering that the PPD file associated with the named driver was actually extracted and saved in text form in /etc/cups/ppd and named the same thing as the queue name. Then I examined the file /etc/cups/ppd/queuename.ppd and found that file contains identifiable text such as:
  • NickName: "HP LaserJet 1320 series Postscript (recommended)"
Which the original PPD file would have contained.

makenicknames.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=8external link
This file parses through all the files in /usr/share/cups/model (even those which are compressed) and generates a csv file containing the NickName as the first field and the full file path it was found in as the second field. This was a part of the puzzle of how to identify the original PPD file used to create a printer.

nicknames.tar.gz

http://www.javacrypt.com/tiki-download_file.php?fileId=9external link
This is a resulting nicknames.csv file from my system generated by makenicknames.pl. Compressed since it's original size is 664.4KB

printerlist.csv

http://www.javacrypt.com/tiki-download_file.php?fileId=6external link
This is a sample printer creation csv file used by createprinters.pl. There is actually only one printer indicated in it
but it should be enough to give you the idea.

My first printerlist.csv was hand crafted by first manually adding a printer of a particular make and model so I could identify the PPD file used and then creating entries in the csv file for all printers of that make and model and specifying this same PPD file.

validatecsv.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=14external link
This is basically the same logic as is run in createprinters.pl but without actually creating any printers. It runs much faster and allows you to resolve errors in the printerlist.csv before starting to create any printers.

printercreategen.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=7external link
This script actually came much later and is designed to automate the process of creating the printerlist.csv by using the nicknames.csv file and parsing through the /etc/cups/printers.conf file for the printer queue, location, description and DeviceURI (ip or dns name and port etc..). It is actually much easier to create a printer interactively, export the printers to create this csv and then use the information from that to compose a list of similar printers to create. Once all the printers exist in one system a new export would give you everything you would need to set up the same exact printer list on another server. Or you could easily create a new file with a subset of these if you only want some of them on another server.

On the subject of replication to other servers keep in mind the same PPD files found in sub folders of /usr/share/cups/model would have to exist on the other servers.

setdefaultoptions.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=10external link
Of course when creating printers in this way none of the printer options such as default paper size or default tray etc. are set to anything other than the defaults indicated in the PPD file from the factory. Rather than struggle with editing the compressed PPD files located in /usr/share/cups/model and then worrying about if they get overwritten or are not the same on every server I wrote this script which allows me to work through the same printerlist.csv file and set desired options such as default paper size for all the printers. In my case all I cared about was setting DefaultPageSize to letter and only if it was set to A4. In any case the script is designed in such a way as to permit you to alter it to adjust virtually any common setting across printers.

deletequeue.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=16external link
I needed a way to clean up existing printers off of a server before importing a new printerlist.csv. This was an effort to delete just one printer and is called from other projects later so it still exists.

deleteallqueues.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=11external link
This is the clean up script using the /etc/cups/printers.conf to provide a list of printers to delete. Not knowing who
will be running this I have put some small amount of warnings into the script.

foundstopped.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=12external link
In my system, once it was operational for some reason I was regularly finding printers in the "stopped" condition. At first no one else had access to the CUPS administration so it was resulting in a support call to me and requiring my manual intervention. This script was simply used to help me identify all the stopped printers in the system. I can only surmise that the printers were being stopped because they were put off line by someone trying to clear a paper jam or some such thing.

startprinters.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=13external link
This was a real time saver and it hasn't come back to bite me as yet. From a cron job this script is run every 10 minutes and it simply parses through the /etc/cups/printers.conf determining if a printer is stopped and attempting to start it.

canceljobs.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=15external link
This script is used to cancel all jobs for a particular queue. Sometimes a script, application or person will continue trying to print to a printer that is either shut off or removed for one reason or another. After the queued list of jobs gets too large (not an easy to find issue) all printing on all printers configured in CUPS suddenly stops. The symptom is usually a call about a printer refusing to accept a new job or refusing to stay started. That printer isn't usually the one with a million unprocessed jobs so its often hard to determine what on earth is happening. Once you do find the printer with the unprocessed jobs the task of clearing them in the CUPS administration web page is simply too tedious and slow especially considering everyone is waiting. So you resort to the command line. Now what was that command again? This script encapsulates it so I don't have to struggle to remember.

Printer Replication Project

Before long other administrators started fiddling in the system and I could no longer sort out some of the skipped steps they did while adding a printer through the CUPS interface. Things such as not setting the DefaultPageSize or not configuring the same printer or with the same PPD file on other servers in the batch. For starters I had to disable system-config-printers as that (Redhat management) takes over printer management and overwrites the /etc/cups/cupsd.conf file amoung other things with security settings that would prevent the CUPS webpage access from other configured subnets for example. Then I built a series of scripts that detect newly added or deleted printers and performs steps such as setting the DefaultPageSize and replicating this change to others servers.
Now anyone who adds (or deletes) a printer does so on a master server and the scripts take care of the rest.

printersync.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=17external link

printersyncslave.pl

http://www.javacrypt.com/tiki-download_file.php?fileId=18external link

deletedprintersync

http://www.javacrypt.com/tiki-download_file.php?fileId=19external link

deletedprintersyncslave

http://www.javacrypt.com/tiki-download_file.php?fileId=20external link

These scripts are designed only to replicate printers from the master to the slaves. It doesn't stop someone from managing printers independently on the slave so long as they don't use a naming standard for those printers that would permit their printer being overwritten from the master. Changes in the slaves are not caught or replicated back to the master.

Ultimately if the slave gets too far out of touch with the master (for whatever reason) it is easy just to clear the printers, and recreate them from an export of the master's printers. It is also a good practice for backup or auditing purposes to occasionally export from the master and slaves. This permits comparison of the printer lists and allows recovery if unknown numbers of printers are accidentally removed or modified.