Difference between revisions of "Add Printers Via Network Script"

From ubermix Wiki
Jump to: navigation, search
(Tweaking the default options)
(Edit the script)
Line 48: Line 48:
  
 
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  
 
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 CES-A2 /etc/hostname
+
  if grep TES-RM46 /etc/hostname
replacing "CES-A2" with the stem of the name for computers that all share the same printer. Replace the lpadmin line below that if statement wit 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).
+
replacing "TES-RM46" with the stem of the name for computers that all share the same printer. Then in the second if statement:
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 4 lines (elif, then, lpadmin -p, lpadmin -d).
+
if ! grep 172.16.20.150/TES-RM46-HP1606DN /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
  
The first if statement and the line near the end that start with "sudo echo" just make sure that each computer only runs this update once. If a computer is restored it will run the script and install the correct printer.
+
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.
  
 
  #!/bin/bash
 
  #!/bin/bash
if [ ! -e /etc/cups/updated.txt ]
+
#Script for adding a printer to TES-RM46 computers
then
+
if grep TES-RM46 /etc/hostname
if grep CES-A2 /etc/hostname
+
then
then
+
if ! grep TES-RM46-HP1606DN /etc/cups/printers.conf
lpadmin -p RoomA2 -v socket://10.6.64.103:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd -L "Room A2" -E
+
then
lpadmin -d RoomA2
+
lpadmin -p Room46 -v socket://10.6.64.103:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_Pro_P1606dn.ppd -L "Room 46" -E
elif grep CMS-D1 /etc/hostname
+
lpadmin -d Room46
then
+
fi
lpadmin -p RoomD1 -v socket://10.6.64.106:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd -L "Room D1" -E
+
fi
lpadmin -d RoomD1
 
elif grep CMS-D8 /etc/hostname
 
then
 
lpadmin -p RoomD8 -v socket://10.6.64.102:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_Pro_P1606dn.ppd -L "Room D8" -E
 
lpadmin -d RoomD8
 
fi
 
sudo echo > /etc/cups/updated.txt
 
fi
 
 
 
  
 +
#Script for adding a printer to TES-C1 computers
 +
if grep TES-C1 /etc/hostname
 +
then
 +
if ! grep TES-RM58-HP1505N /etc/cups/printers.conf
 +
then
 +
lpadmin -p Room58 -v socket://10.6.64.104:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_P1505n.ppd -L "Room 58" -E
 +
lpadmin -d Room58
 +
fi
 +
fi
  
 
== Tweaking the default printing options ==
 
== Tweaking the default printing options ==

Revision as of 15:18, 18 September 2013

If you have set up your ubermix computers to run the .network-autostart script (see Auto_Update_Script ) and look for an update.sh 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.

Prerequisites:

  • 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, 10.6.64.103 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://10.6.64.103:9100 -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 172.16.20.150/TES-RM46-HP1606DN /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.

#!/bin/bash
  1. Script for adding a printer to TES-RM46 computers

if grep TES-RM46 /etc/hostname then if ! grep TES-RM46-HP1606DN /etc/cups/printers.conf then lpadmin -p Room46 -v socket://10.6.64.103:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_Pro_P1606dn.ppd -L "Room 46" -E lpadmin -d Room46 fi fi

  1. Script for adding a printer to TES-C1 computers

if grep TES-C1 /etc/hostname then if ! grep TES-RM58-HP1505N /etc/cups/printers.conf then lpadmin -p Room58 -v socket://10.6.64.104:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_P1505n.ppd -L "Room 58" -E lpadmin -d Room58 fi fi

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://192.168.1.9/Room407 -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 updates.sh file. It encourages more environmentally friendly printing!