Choose your language

Choose your login

Support

Copying Printer Config from one Apple Mac To Another

THE PAGE APPLIES TO:

The printer configuration information on Mac OS X is stored in the directory:

/etc/cups

This is a “hidden” system directory storing the CUPS configuration. Recursively copying this directory from one system to another will duplicate the printer configuration. Mac OS X administrators may find the following shell script example useful. It uses a secure shell (ssh) to pull and duplicate the printer configuration from a master/source system. This script will work with most printers that use standard PPD based drivers, but may have problems with some drivers that use custom components (e.g. Epson wide-format printers).

How to use:

1) Copy script (contents below) into a file called pull-printer-config.sh on a target system (the system that needs the printer config). Verify that Remote Login is enabled on the Mac that currently has the printer configured for the admin user you’ll be logging in as. You can enable Remote Login in System Preferences > Sharing > Remote Login.

2) Make sure the Printer Setup Utility is closed.

3) Open a command-prompt and cd to this directory.

4) Run the script:

           sudo sh pull-printer-config.sh <sourcemachine> <adminuser>

where:

<sourcemachine> is the name or IP of the system who’s printer config you’d like to copy.

<adminuser> is the name of an “admin” level account on the source system. You will need to know the password associated with this account.

Tip: Advanced administrators may choose to take advantage of SSL host keys and a custom /etc/sudoers file to avoid the need to enter a password.

The script:

Copy the contents below into a plain text file called pull-printer-config.sh

#!/bin/sh
#
# (c) Copyright PaperCut Software, 2007
#
# Author: Chris Dance (chris.dance <a> papercut.com)
# A simple script to copy printer configuration from one Apple Mac OS X 
# system to another.
#

TARGET_HOST=hostname SRC_HOST=$1 SRC_USER=root

if [ -z “${SRC_HOST}” ]; then echo echo “USAGE: pull-printer-config SOURCE [USER]” echo " SOURCE: The remote system whose printer config you’d like to copy." echo " USER: An admin level user on the source system. If not defined root is used." echo exit 1 fi

if [ ! -z “$2” ]; then SRC_USER=$2 fi

userid=id | sed "s/^uid=\([0-9][0-9]*\).*$/\1/" if test “${userid}” -ne 0; then echo “Error: Please run this script as root (e.g. sudo pull-printer-config)” 1>&2 exit 1 fi

echo “Copying printer configuration from ${SRC_HOST} to ${TARGET_HOST}.” echo “Enter the password for the user ${SRC_USER} on ${SRC_HOST} if requested.” echo “You may be requested for your password multiple times.” echo

On the target system take a copy of our cups config and set ourselves as the

owner.

echo “Preparing config on source server…” ssh -t “${SRC_USER}@${SRC_HOST}”
“sudo sh -c
"rm -fr /tmp/cupstmp; cp -R /etc/cups/ /tmp/cupstmp; chown -R ${SRC_USER} /tmp/cupstmp"”

if [ “$?” -ne “0” ]; then echo “Error: Unable to source config of remote system” 1>&2 exit 1 fi

Use scp to copy our temp copy over to our local system.

echo “Copying config…”

rm -fr /etc/cupstmp >/dev/null 2>&1

Move old config

scp -rpq “${SRC_USER}@${SRC_HOST}:/tmp/cupstmp/” “/etc/cupstmp” if [ ! -d /etc/cupstmp ]; then # # Error so restore our backup # echo “Error: Unable to copy files.” 1>&2 exit 1 fi

datestamp=date +%y%m%d mv /etc/cups “/etc/cups${datestamp}” && mv /etc/cupstmp /etc/cups

Restart the CUPS server so it picks up our new config.

killall -HUP cupsd

echo “Copy complete.”


Categories: How-to Articles , Scripting and APIs , Print Queues


Keywords: duplicate , deploy , automate printer configuration

Comments

Last updated June 13, 2024