You are here:

Unix/Linux OS/Unix Shell scripts for adding printer or print queues


QUESTION: Dear Nix, i am very new in UNIX and shell programming. I need help to build shell scripts to add multiple printer or print queue to a server in one script. This list of printers and its UNIX number have to follow the same list from another server. and the type of printer machines that i want to add have two types, Fuji-xerox and HP-printers. I have no idea how to create such scripts, please help.

Thank you.

ANSWER: Hi Fairul.

Firstly, you did not say which printing system your Linux servers are using. I assume it is CUPS. Secondly, you did not say if all of the printers are network printers or if there are local printers.

I do not understand what is wrong with the regular GUI. Why not use it? You have to specify the IP addresses and printer names by hand, so what is the benefit of a script? You'll do this only once, right?

In any case, a script can manipulate /etc/cupsd.conf or whatever the location of the file is. But it will be error prone and it is best done either manually or via GUI. So that you really know what you are doing.

---------- FOLLOW-UP ----------

Apologize for my lack of details in the previous question. Yes the printers are network connected. The scenario is like this: This UNIX server is running a Solaris 10 OS with SAP System. As one day it might go down due to power/system failure and I am planning to build a script to recreate all the print queue in a second server by running a script. Let say the printers that will going to be recreate is around 80 printers and the information that will be needed is the printer name and IP number to create the print queue. This list of printers and its IP number form the first server will be kept in a list in the second folder. I agree with you that it is the best to create it manually, but I am thinking of a script to create all at once. Please help. Thank very much.


Let us assume that you have a list of IPs and names in a file, separated by ":", like this:

then the script would be something like:



cat ${FILE} | while read line; do
    host=`echo line | cut -f1 -d:`
    queue=`echo line | cut -f2 -d:`
    /usr/sbin/lpradmin -p ${host} -v ipp://${host}/${queue}

This can now be expanded, of course, you can add logical printer names, instead of host names. You can also make the script self contained, using arrays:


PRINTERS=('' '')

for line in "${PRINTERS[@]}"; do
    host=`echo line | cut -f1 -d:`
    queue=`echo line | cut -f2 -d:`
    /usr/sbin/lpradmin -p ${host} -v ipp://${host}/${queue}

So, have fun.

Unix/Linux OS

All Answers

Answers by Expert:

Ask Experts




UNIX, programing, C, C++, awk, shell scripts, Web, HTTP, Apache, firewall, AltaVista firewall, E-Mail, sendmail, IMAP4 POP3, DNS, NTP, system administration, TCP/IP, security


Digital UNIX
AltaVista Firewall


©2017 All rights reserved.