Updating printers on user's machine to point new print server after print server migration.

ManjunathKosigi
New Contributor II

Hi,

We are migrating print server in our environment, on existing server we have around 20 printers configured and users have mapped printers according to their requirement. We want to migrate the printer on the user’s machine to new servers from the existing server.
I need help to fetch the configuration settings of the existing printer, so that I can recreate same for new printer.
I created below script to get the printer name and destination from the machine and modify the name and destination to new print server and create new printer on the machine. However after script execution the new printer is appearing in the terminal (lpstat –v) but not in the printer preference of the machine.
Thanks in advance.

#!/bin/sh
print_names=('ABCPS02_ABCP1-32310_HPM553' 'ABCPS01_ABCP1-32310_HPM553' 'ABCPS02_ABCP1-2450_HPM233')
old_server1="ABCPS01"
New_server1='ABCPS01P'
old_server2="ABCPS02"
New_server2='ABCPS02P'
Default_printer=$(lpstat -d |awk '{print $4}')

for print_name in "${print_names[@]}"; do

    if [[ "${print_name}" = +(ABCPS01*|ABCPS02*) ]]; then

        if [[ $print_name == "ABCPS01"* ]]; then

            New_printer="${print_name/$old_server1/$New_server1}"
            old_printer_adderss=$(lpstat -v $print_name |awk '{print $4}')
            New_printer_adderss="${old_printer_adderss/$old_server1/$New_server1}"
          #  echo "creating new printer $New_printer"
            lpadmin -p $New_printer -D $New_printer -v $New_printer_adderss
          #  echo "remove existing printer $print_name"
            lpadmin -x $print_name 
            if [[ $print_name == $Default_printer ]]; then
                lpoptions -d $New_printer
            fi
        fi

        if [[ $print_name == "ABCPS02"* ]]; then

            New_printer="${print_name/$old_server2/$New_server2}"
            old_printer_adderss=$(lpstat -v $print_name |awk '{print $4}')
            New_printer_adderss="${old_printer_adderss/$old_server2/$New_server2}"
         #   echo "creating new printer $New_printer"
            lpadmin -p $New_printer -D $New_printer -v $New_printer_adderss
          #  echo "remove existing printer $print_name"
            lpadmin -x $print_name 
            if [[ $print_name == $Default_printer ]]; then
                lpoptions -d $New_printer
            fi
        fi
    fi
done
Mkosigi
1 ACCEPTED SOLUTION

Chris
Valued Contributor

How about modifying the existing printers instead of deleting and recreating them?
I believe I did that once, something like

/usr/sbin/lpadmin -v "$NewPrinterURL" -d "$Printer"

View solution in original post

2 REPLIES 2

Chris
Valued Contributor

How about modifying the existing printers instead of deleting and recreating them?
I believe I did that once, something like

/usr/sbin/lpadmin -v "$NewPrinterURL" -d "$Printer"

DBrowning
Valued Contributor II

If the printer share names are the same, we have used this with great success in the past...

#!/bin/sh

launchctl unload -w /System/Library/LaunchDaemons/org.cups.cupsd.plist
cp /etc/cups/printers.conf /etc/cups/printers.conf.bak
sed -i '' 's//old_Server_Address///new_Server_Address//g' /etc/cups/printers.conf
launchctl load -w /System/Library/LaunchDaemons/org.cups.cupsd.plist