Add Printers Via Network Script

From ubermix Wiki
Jump to: navigation, search

If you have set up your ubermix computers to run the .network-autostart script (see Auto_Update_Script ) and look for an when they boot up, you can do updates and customization. One option is to have the correct printer pushed out to a computer based on its hostname.


  • Network-autostart file set up on your image
  • Computers are named with some convention based on location. This can be set after imaging, by choosing Advanced Options (5) and then Set device hostname (5). For example the convention, SCHOOLABBREVIATION-ROOM-COMPUTERNUMBER, would have computers named CES-A2-01 for a computer at Central Elementary School in Room A2.


First determine the correct printer driver

Open a terminal (ctrl-alt-t) and type

lpinfo --make-and-model 'Part of your printer model name here' -m

For example

lpinfo --make-and-model '1022n' -m 

Will find the drivers for the HP Laserjet 1022n You will see a long list of text for multiple drivers, but the top one is the recommended driver

foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd HP LaserJet 1022n Foomatic/foo2zjs-z1 (recommended)
drv:///hpijs.drv/hp-laserjet_1022n-hpijs-pcl3.ppd HP LaserJet 1022n hpijs pcl3, 3.12.6, requires proprietary plugin
drv:///hpijs.drv/hp-laserjet_1022n-hpijs-zjs.ppd HP LaserJet 1022n hpijs zjs, 3.12.6, requires proprietary plugin
drv:///hpcups.drv/hp-laserjet_1022n-pcl3.ppd HP LaserJet 1022n pcl3, hpcups 3.12.6, requires proprietary plugin
drv:///hpcups.drv/hp-laserjet_1022n-zjs.ppd HP LaserJet 1022n zjs, hpcups 3.12.6, requires proprietary plugin
foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022nw.ppd HP LaserJet 1022nw Foomatic/foo2zjs-z1 (recommended)
drv:///hpijs.drv/hp-laserjet_1022nw-hpijs-pcl3.ppd HP LaserJet 1022nw hpijs pcl3, 3.12.6, requires proprietary plugin
drv:///hpijs.drv/hp-laserjet_1022nw-hpijs-zjs.ppd HP LaserJet 1022nw hpijs zjs, 3.12.6, requires proprietary plugin
drv:///hpcups.drv/hp-laserjet_1022nw-pcl3.ppd HP LaserJet 1022nw pcl3, hpcups 3.12.6, requires proprietary plugin
drv:///hpcups.drv/hp-laserjet_1022nw-zjs.ppd HP LaserJet 1022nw zjs, hpcups 3.12.6, requires proprietary plugin

You then copy the first bit of text all the way to .ppd In the laserjet example you would copy the following text and paste it in a text file for later foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd

Second determine your printer ip address

Usually printers are set up with static IP addresses. If so you can ask your IT team for a list of IP addresses for printers. Also most printers will print out their configuration or have a display that will show the configuration. Printer IP addresses will be a series of 4 numbers separated by periods. For example, Once you have the IP address you are ready to push out printers over the network

Edit the script

Here is the basic script that you can change with your site information. The terminal command that will add a printer looks like this:

lpadmin -p RoomA2 -v socket:// -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd -L "Room A2" -E

Replace 4 pieces of information as shown below.

lpadmin -p ReplaceWithPrinterName -v socket://put-IP-address-here:9100 -m put-driver-.ppd-file-here -L "Put the location here" -E

Now once you have a correct line of code for each printer you can edit the script below to install a different printer to each set of computers. Edit the lines that say

if grep TES-RM46 /etc/hostname

replacing "TES-RM46" with the stem of the name for computers that all share the same printer. Then in the second if statement:

if ! grep /etc/cups/printers.conf

replace the content between grep and /etc/cups/printers.conf with the address or name of the printer, so it reads:

if ! grep SomePartOfPrinterName /etc/cups/printers.conf

Replace the lpadmin line below that if statement with the lpadmin line for your printer name, IP address, and driver. Change the lpadmin -d line to the same name as the printer you installed (this sets the printer as the default). Repeat this step for each room of computers. The following lines start with the word elif instead of if. If you need to add more room options just copy more blocks of 8 lines.

The first if statement asks if a computer is named a certain name (so if your computers are named by room, then all computers in a room will get the update). The second if statement checks if the printer exists on the computer already and if not, it adds the printer.

#Script for adding a printer to TES-RM46 computers
if grep TES-RM46 /etc/hostname
	 if ! grep TES-RM46-HP1606DN /etc/cups/printers.conf
		 lpadmin -p Room46 -v socket:// -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_Pro_P1606dn.ppd -L "Room 46" -E
		 lpadmin -d Room46

#Script for adding a printer to TES-C1 computers
if grep TES-C1 /etc/hostname
	 if ! grep TES-RM58-HP1505N /etc/cups/printers.conf
		 lpadmin -p Room58 -v socket:// -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_P1505n.ppd -L "Room 58" -E
		 lpadmin -d Room58

Tweaking the default printing options

In some cases, you might want to change the default printing options. These options are driver dependent, so a fair amount of trial and error is needed.

For our requirements, we found that our driver's default of 1200x1200 resolution was creating huge print jobs and overloading our network. The printers were also taking up enormous amounts of time to process each job. Using a couple of additional lpadmin commands solved the issue:

   lpadmin -p Room407 -v smb:// -E -m drv:///hpcups.drv/hp-laserjet_p4515tn.ppd -L "ES 4th Floor Printer"
   lpadmin -p Room407 -o OptionDuplex=True -o PageSize=A4 -o PrintoutMode=Normal.Gray -o Duplex=DuplexNoTumble -o printer-is-shared=false
   lpadmin -p Room407 -o ColorModel=Grayscale -o PrinterResolution=300x300dpi

These commands run in a very short time, and so we let them run every time in the file. It encourages more environmentally friendly printing!

Personal tools