Using the following bash script you can install multiple printers, on multiple servers. Each printer has its own description, location, PPD file (driver) and network path.

All of these details are stored in a file called “printers.txt”, which is a TAB separated, 4 column list.

Contents of printers.txt look like this:

PR01    HPLJ4000    Office Printer     
PR02    HPLJ4000    Accounting Printer (Mary)
LP02    HPLJ4000    Warehouse (Mike)   
SP12    HPLJ4000    Main Floor         
LP01    HPLJ4000    Visitors Color Printer

First column is printer name, 2nd column is driver name, 3rd column is printer description, 4th column is network path.

DO NOT add blank lines at the end of printers.txt!

The bash script ( looks like this:

for serverip in;
  while IFS=$'\t' read -r -a prndata;
      echo "Copying PPD from local to $serverip…"
      scp ${prndata[1]}.ppd username@$serverip:/tmp/
      echo "Connecting to $serverip and installing printer ${prndata[0]} (${prndata[2]}) using file /tmp/${prndata[1]}.ppd…"
      ssh -n -oStrictHostKeyChecking=no username@$serverip "sudo lpadmin -p ${prndata[0]} -E -v lpd://${prndata[3]} -P /home/ibmadmin/${prndata[1]}.ppd -L \"${prndata[2]}\"";
      echo "Installed $count printers until now. Remote IP is: $serverip"
    done < echo $HOME/printers.txt
echo "DONE!"

prndata is an array which includes every column of printers.txt. First column is ${prndata[0]}. As you can see from the above script, first we define serverip (the IP of each server the printers must be installed on).

The PPD file (printer driver) is transfered to the remote server (via SCP command), on /tmp/ folder. Then it will be used to install the printer, using lpadmin.

In this example, the script will install the 5 printers (which are defined in printers.txt) on each of the 3 servers from serverip variable.

In order for this script to work properly, please consider the following:

– adjust username and paths to your needs

– put the script in the same folder with .ppd files

– name the .ppd files according to the second column in printers.txt (e.g. HPLJ4000.ppd)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.