1836768 Members
2241 Online
110109 Solutions
New Discussion

Moving Printers.

 
SOLVED
Go to solution
Patrick Ware_1
Super Advisor

Moving Printers.

Hello,

I have 311 printers to define on severs A, B, and C. The printers needing to be defined are already setup on an existing server,D. The problem I have is that I don't need to define ALL printers from server D to A,B, and C, just the specified 311. How would I accomplish this? Is it even possible?
17 REPLIES 17
Patrick Ware_1
Super Advisor

Re: Moving Printers.

By the way, these printers were added using jetadmin/jetdirect.
Bill Hassell
Honored Contributor

Re: Moving Printers.

Actually very easy with JetDirect printers. The command is addqueue and found in the same directory as hppi (or if you are using the obsolete jetadmin /opt/hpnp/bin). Start by making a list of the printers and their IP or hostname:

JETDIR=/opt/hpnpl
for MYPRN in /etc/lp/interface
do
MYHOSTIP=$(grep PERIPH= $MYPRN)
if [ $? -eq 0 ]
then
echo "$JETDIR/bin/addqueue -h $MYHOSTIP -q $MYPRN"
fi
done

If you do not have the hpnpl directory, change the first line to /opt/hpnp. The output of the above script contains the command line needed to add the printer on a new server. Just edit out the undesired printers and copy the resultant file to the new server.


Bill Hassell, sysadmin
Basheer_2
Trusted Contributor

Re: Moving Printers.

Patrick,

I did this few months ago to move about 105 printers from (11.11) to 11.23

so far now problems.
How to move all printers to another server DocId: KBRC00017466 Updated: 12/14/05 9:57:00 AM

PROBLEM
How to move all printers to another server?
RESOLUTION
HP does not support the copying of the lp spooler configuration from one system
to another. The following suggestions have been known to work in many cases.

If possible use SAM to create a backup of your printer configuration that
can be restored on another system, see document:
UPRTKBRC00014862 How to move the lp spooler configuration to another system


If SAM fails the spooler directories can be copied between systems of the
same OS version. If you have JetDirect network printers attached, ensure both
servers have JetDirect Printer Installer software installed.

On the source server, backup using tar, these directories:

/etc/lp/
/var/spool/lp

Example:

# lpshut
# tar cvf /tmp/etc_lp /etc/lp/*
# tar cvf /tmp/var_spool_lp /var/spool/lp/*
# lpsched

Use ftp in binary mode to copy the following files to your destination
server:

/tmp/etc_lp
/tmp/var_spool_lp

On the destination server, restore those directories after removing any
previous printer configurations:

# lpshut
# rm -r /etc/lp
# rm -r /var/spool/lp
# tar xvf /tmp/etc_lp
# tar xvf /tmp/var_spool_lp
# lpsched

Basheer_2
Trusted Contributor

Re: Moving Printers.

Patrick,

This is the Doc, HP Sent Me
and this is the one, I followed
UPRTKBRC00014862
How to move the lp spooler configuration to another system
Document Information Table
How to move the lp spooler configuration to another system DocId: UPRTKBRC00014862 Updated: 12/1/04 7:44:00 AM

PROBLEM
How can the lp spooler configuration be moved or copied to another
system? Recreating each printer in the current configuration on the new system
requires a lot of effort..

RESOLUTION
HP does not support the copying of the lp spooler configuration from one system
to another. The IO configuration of the target system may be different than IO
configuration on the source system. The device files for local printers would
be different on the new system, and the spooler configuration for those
printers contain the device files. The print queues may not work.

A procedure that has been known to work in most circumstances is as follows :

On the source system:

Execute
-> SAM
-> Printers and Plotters
-> Lp Spooler
-> Save/Restore Spooler Configuration

Choose
-> Actions
-> Save Spooler Configuration

This will save all the information necessary to rebuild the spooler into the
directory /var/sam/lp.

Tar this directory (/var/sam/lp) :

# tar cvf /tmp/lp.tar /var/sam/lp

Copy the resulting tar file, lp.tar, onto the target system.

Unpack the lp.tar file on the target system :

# tar xvf lp.tar


Execute
-> SAM
-> Printers and Plotters
-> Lp Spooler
-> Save/Restore Spooler Configuration

Choose
-> Actions
-> Restore Spooler Configuration

This will build the lp spooler configuration on the target system using the
information from the source system, creating a "clone" of the old system.

If any source system print queues are network printers originally configured
using HP JetAdmin or HP JetDirect Printer Installer, then the
following must also be performed.

HP JetDirect Printer Installer must be installed on the destination
system.

Run the following command after restoring the printer/spooler
configuration through SAM:

# /opt/hpnpl/bin/transferqueue local
Enter the queue name or all to modify all the queues : all

NOTE: transferqueue changes several paths in the JetAdmin model scripts in
/etc/lp/interface/ and /etc/lp/interface/model.orig/ to point to the location
of the HP JetDirect Printer Installer product.

An error may occur when restoring the spooler if the root umask is set to
something other than 022. The permission on /var/sam/lp and all file
under it could be changed from their defaults, with the result that SAM cannot
access the files to perform the restore. The permissions on /var/sam/lp and the
files under it should be 755 or rwxr-xr-x, with the owner root and group
sys.

# ll -d /var/sam/lp
drwxr-xr-x 8 root sys 8192 Nov 29 15:45 /var/sam/lp

The error received in SAMlog would be something like:

ERROR A problem occurred doing
"lpadmin -ptrec_stor -i/var/sam/lp/interface/trec_st or -v/dev/null ".

Stderr from this command is
"/usr/sbin/lpadmin: can't access file "/var/sam/lp/interface/trec_stor"".

* Failed to restore trec_stor.

Another error that may occur, and has the same root problem, is:

ERROR A problem occurred doing
"lpadmin -pPRINTER -i/var/sam/lp/interface/PRINTER -v/dev/null ".

Stderr from this command is
"/usr/sbin/lpadmin: can't access file /var/sam/lp/interface/PRINTER"

* Failed to restore PRINTER.

A second way to resolve this particular error is to change the owner and group
of /var/sam/lp to lp and bin.

chown -R lp:bin /var/sam/lp

A better solution would be to set the proper permissions on the directory and
files with:

chmod -R 755 /var/sam/lp


Patrick Ware_1
Super Advisor

Re: Moving Printers.

Bill,

How should me list look, or be formated?
Bill Hassell
Honored Contributor

Re: Moving Printers.

The code I listed will produce a ready-to-use script that looks something like this:

/opt/hpnpl/bin/addqueue -h 12.34.56.78 -q lj4bay6

and so on. The documents listed above are used for a complete move--no editing. This would be necessary if oyu had a mix of local, remote and JetDirect printers. But since all your printers are JetDirect, the task is much simpler and you can edit the rsultant file before you add the printers to the new system.


Bill Hassell, sysadmin
Patrick Ware_1
Super Advisor

Re: Moving Printers.

You will have to forgive me, but I am a novice scripter. I ran the script, and saw no output, and do not know where to look for such. What am I supposed to see?
Patrick Ware_1
Super Advisor

Re: Moving Printers.

Ok, I added an "else" statement to the script, and now I know why I am not getting any output.

#!/usr/bin/ksh
JETDIR=/opt/hpnp
for MYPRN in /etc/lp/interface
do
MYHOSTIP=$(grep PERIPH= $MYPRN)
if [ $? -eq 0 ]
then
echo "$JETDIR/bin/addqueue -h $MYHOSTIP -q $MYPRN"
else
echo "$JETDIR/bin/addqueue -h $MYHOSTIP -q $MYPRN"
fi
done

After I run the command, I get the following output:

root@D:/> ./ip_printer.sh
/opt/hpnp/bin/addqueue -h -q /etc/lp/interface

This lets me know that the if statement didn't return with the right code. I now assume that you were expecting the printer queue names to be the same as what the address defined in the config file in /var/sam/lp/interfaces directory? Please advise. I am in a time crunch now.
Patrick Ware_1
Super Advisor

Re: Moving Printers.

Ok,

I changed up the script a little to read from a list of the printers that I have:

#!/usr/bin/ksh
JETDIR=/opt/hpnp
for MYPRN in `cat /home/pw3483/tools/printers.txt`
do
MYHOSTIP=$(grep PERIPH= /var/sam/lp/interface/$MYPRN)
if [ $? -eq 0 ]
then
echo "$JETDIR/bin/addqueue -h $MYHOSTIP -q $MYPRN"
else
echo "$JETDIR/bin/addqueue -h $MYHOSTIP -q $MYPRN"
fi
done


Here is sample output:

/opt/hpnp/bin/addqueue -h PERIPH=192.168.1.28
PERIPH=$MODEL -q wiwiggp02

I can get rid of the first "PERIPH=" easily by doing a search and replace. The issue I am having now is keeping the PERIPH=$MODEL from showing up in the output at all. How can I accomplish that? This is how the output should look:

/opt/hpnp/bin/addqueue -h PERIPH=135.218.204.28 -q wiwiggp02

Please help!!


Bill Hassell
Honored Contributor

Re: Moving Printers.

The directory /etc/lp/interface has a set of printer scripts, each named for the local printer queue. Since you said that all these printers were added using JetDirect software, each queue in that directory will have the variable PERIPH being assigned the IP address or hostname of your printer. My script will produce nothing if the keyword PERIPH is not present. Look at any of the scripts in the interface directory. They should have a header at the top that mentions the Network Printer and the control program hpnpf. If the script contains information about remote printers, then the printers were not added as HP JetDirect printers (in SAM they are called network printers). Post the first 20 lines of one of the printer scripts in /etc/lp/interface.


Bill Hassell, sysadmin
Patrick Ware_1
Super Advisor

Re: Moving Printers.

Here is a sample output from one of the printer scripts in /etc/lp/interface:

root@erie:/etc/lp/interface> head -20 4100bl07
#!/usr/bin/sh

# (c) Copyright 1992, 1993, 1994 Hewlett-Packard Company. All Rights Reserved.

# $Header: /users/hpnp/odyssey/repository/sh/hpnp.model.psh,v 1.18 1999/04/21 08:40:27 hpnp Exp $
#
# HP JetAdmin Utility for Unix, HP-UX Network Printer Control Script
#
# This script invokes the original model script from the
# subdirectory model.orig and pipes its output to hpnpf.

if echo $PATH | grep "/usr/bin" > /dev/null 2>&1
then
:
else
PATH=$PATH:/usr/bin
export PATH
fi

# Add bin to the path for systems with /bin


BTW, in my question above this one, how do I keep "PERIPH=$MODEL" from appearing in the output? I think if I could do that, this problem would be over.
Patrick Ware_1
Super Advisor

Re: Moving Printers.

All the files I have viewed have the PERIPH=address in them. In both locations (/etc/lp/interface and /var/sam/lp/interface)
OldSchool
Honored Contributor

Re: Moving Printers.

I neccessary change from:

MYHOSTIP=$(grep PERIPH= $MYPRN)

to

MYHOSTIP=$(grep PERIPH= $MYPRN | grep -v MODEL)
Bill Hassell
Honored Contributor

Re: Moving Printers.

Since you already have the list of printers, all you need is the IP addresses. The script you displayed is indeed a JetDirect script but I don't have access to a system at the moment. Use:

cd /var/sam/lp/interface
grep MODEL 4100bl07

to locate where MODEL is assigned. All we're doing here is to locate the printer's IP address. Show this item and then I can modify the script to obtain the hostname or IP address.

On the other hand, if you already have the local HP-UX print queues (the printer names) corresponding to either /etc/hosts or your DNS server (so that nslookup 4100bl07 will return an IP address), you have a much simpler task. Let us know.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor
Solution

Re: Moving Printers.

OK, I found a system. There are two PERIPH lines in the basic JetDirect model script. They look like this:

PERIPH=myhostORip
PERIPH=$MODEL

However, the $MODEL line is not in column 1 so my script would be modified to:

JETDIR=/opt/hpnpl
for MYPRN in /etc/lp/interface
do
MYHOSTIP=$(grep ^PERIPH= $MYPRN | cut -d= =f2)
if [ $? -eq 0 ]
then
echo "$JETDIR/bin/addqueue -h $MYHOSTIP -q $MYPRN"
fi
done

There are two changes: one is the addition of ^ in front of the PERIPH= string to find only the line which has the IP address or IP assigned. The other is an oversight in the original script. $MYHOSTIP should contain only the text following the = sign so MYHOSTIP= now has a cut command at the end. This should produce a ready-to-use file, something like this:

/opt/hpnpl/bin/addqueue -h 12.34.56.78 -q 4100bl07
/opt/hpnpl/bin/addqueue -h 12.34.56.6 -q 4102bl08
/opt/hpnpl/bin/addqueue -h 12.34.56.123 -q 4132bl09

and so on. Just remove the printers you don't want to add from this file, transfer it to the new computer and the run it with: sh myfile


Bill Hassell, sysadmin
Patrick Ware_1
Super Advisor

Re: Moving Printers.

Bill and System Administrator,

Between you two, I got what I needed accomplished!! Thank you.
Patrick Ware_1
Super Advisor

Re: Moving Printers.

Done