Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to delete,create or amend printers on DEV server 1

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
ZA
Need help with script to delete,create or amend printers on DEV server from the PROD server using the lpadmin command.
Senior said i should use the rsh command in my script, to get a list of printers using lpstat -v command.
where do i start?????


 
Your Senior said:
...said i should use the [tt]rsh[/tt] command in my script, to get a list of printers using [tt]lpstat -v[/tt] command.

exactly there, I 'd hazard a guess...

HTH,

p5wizard
 
In my script i start with doing a lpstat -v command on my local machine, this list all the printers i currently have.
I also do a rsh lpstat -v to my remote server for a similar list.
Would a diff of the two .txt files help in ascertaining printers needed to be added,deleted on the local server.
local server .txt file
Code:
device for 0101a01: lpd://172.25.41.111:515
device for 0101a02: lpd://172.25.25.58:515
device for 0101a03: lpd://172.25.41.135:515
device for 0101a04: lpd://172.25.41.195:515
device for 0101a05: lpd://172.25.41.133:515

remote server .txt file
Code:
device for 0101a01: lpd://172.25.41.111:515
device for 0101a02: lpd://172.25.25.58:515
device for 0101a03: lpd://172.25.41.135:515
device for 0101a04: lpd://172.25.41.195:515
device for 0101a05: lpd://172.25.41.133:515

I know i would have to use the lpadmin command to add,delete printers.How do i put it into a shell script?????
 
Delete:
lpadmin -x destination

Create or Amend:
lpadmin -p printer options

Anyway:
man lpadmin

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks...but that i know...
How would i put it into a shell script..
i found this
Code:
function printerExists()
{
  if [ $# -ne 1 ]; then
    echo "Incorrect parameters"
    return 0
  else
    lpstat -p | awk '{print $2}' | while read printer
    do
      if [ $1 = "${printer}" ]; then
        return 1
      fi
    done
  fi	
}
# Printer Name cannot Include any spaces
prName="formalName"
# User friendly printer name"
prDescription="Printer Name"
# Location
prLocation="Home Office"
# IP Address of printer
prAddress="192.168.1.99"
# PPD Filename... assumes it is installed on machine
prPPD="HP LaserJet 2200.gz"

#Test If Printer is already installed
printerExists $prName
prExists=$?

if [ $prExists -eq 1 ]; then
  echo "Printer already exists. Skipping: \"$prName\""
else
  # Add Printer Command 
  lpadmin -p "${prName}" -D "${prDescription}" -L "${prLocation}" \
  -E -v lpd://"${prAddress}" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/$prPPD" \
  -o HPOption_Duplexer=True -o Resolution=1200x1200dpi
fi

how can i put it together...
 
Did the following:
Code:
LOCAL_FILE=`/usr/lbin/lpstat -v >> sun5-printers.txt
Code:
REMOTE_FILE=`rsh sun8 /usr/lbin/lpstat -v >> sun8-printers.txt

I ran this awk for differences between the two files
Code:
awk 'BEGIN {while ( getline < "sun5-printers.txt") {arr[$0]++ }}{ if (!($0
 in arr ) ) {print} }' sun8-printers.txt

output displayed to screen.
Code:
device for 0117bd1: lpd://172.25.29.60:515
device for 2201bl7: socket://172.25.11.170:9100

I need a function to recreate or amend the differences
would this function be a point in the right direction
# Printer Name cannot Include any spaces
prName="printername"
# IP Address of printer
prAddress="192.168.1.99"
# Location
prLocation="Home Office"
#Description
prdescrip=
#filter
prfilter=
#Port
prport=
#Driver
prdriver=

Code:
#Amend,create or delete Printer
printerExists $prName
prExists=$?
function printerExists()
{
if [ $prExists -eq 1 ]; then
  echo "Printer already exists. Skipping: \"$prName\""
else
  # Add Printer Command 
  lpadmin -p "${prName}" -E -D "${prDescript}" -L "${prLocation}" -i /u1/cups/mac/"$prFilter_filter -v \
  "$Port"://"${prAddress}":"Prdriver"
fi

will i have to create another function to delete the printer
using lpadmin -x


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top