Categories
Software

Batch printer installation on multiple servers

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               192.168.15.10
PR02    HPLJ4000    Accounting Printer (Mary)    192.168.10.2
LP02    HPLJ4000    Warehouse (Mike)             192.168.10.3
SP12    HPLJ4000    Main Floor                   10.20.15.10
LP01    HPLJ4000    Visitors Color Printer       10.20.15.24

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 (print.sh) looks like this:

#!/bin/bash
count=0
for serverip in 10.177.33.170 10.177.71.7 10.177.71.17;
do
  while IFS=$'\t' read -r -a prndata;
    do
      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]}\"";
      count=$((count+1))
      echo "Installed $count printers until now. Remote IP is: $serverip"
    done < echo $HOME/printers.txt
done
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.

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