[HPADM] SUMMARY print to a file?

From: Unix-Admin (Unix-admin@triad.rr.com)
Date: Thu Sep 05 2002 - 21:44:32 EDT


Here are the answers
Thanks
Tom

------------------------------------------

Do as follows.

touch /tmp/file_printer
chown lp:bin /tmp/file_printer
chmod 644 /tmp/file_printer
lpadmin -pmyfileprinter -v/tmp/file_printer -mlaserjet

lpshut
lpsched
enable myfileprinter
accept myfileprinter

lp -dmyfileprinter /etc/passwd

Verify it printed..

cat /tmp/file_printer

-------------------------------------------
Take a look at scripts in /var/spool/lp/model (particularly the one called
"dumb") -- they just cat(1) a file to the device specified when you build
the queue (imagine what would happen if that file were on the file system
and the cat was changed from

    cat $file 2>&1

to

    cat $file >> $outfile 2>&1

Or, maybe, you want to store them in individual files using the print job
number...

When you lpadmin, use /dev/null as the device.

Just be careful, PS file are HUGE. They are ASCII files, first line starts
with "%!PS".

-------------------------------------------
i have modified the "dumb" model to print
to a file specified on the lp command line. add it to /usr/spool/lp/model
directory and use it to create a new printer. good luck, julius

#!/usr/bin/sh

# lp interface for dumb line printer modified to allow print to file
#
#added option: -name, use as -nameFILE_NAME, where FILE_NAME is
# fully qualified file name where the output should go
#
#########################################################################
PATH="/usr/bin:/usr/lib"
export PATH

for i in $5
do
case "$i" in
-name | name) # file name
name=$i ;;
esac
done
if [ -n $name ]
then
cat /dev/null > "$file"
else
exit 1
fi

# The remaining arguments are files

shift; shift; shift; shift; shift
files="$*"

# Print the spooled files to $file

for file in $files
cat "$file" >> $name 2>/dev/null
done

exit 0
#### end model file ####

-------------------------------------------------------

Create the print queue with device "/dev/null". For example "lpadmin
-pPRTNAME -mMODEL -v/dev/null".

If you want ASCII text formatted for postscript, then use model
"postscript". If you do not want any formatting done, then use model
"dumb".

Then you can edit the /etc/lp/interface/PRINTER script and change it to
output to a file.

In this script, the $1 through $5 args are JOB, USER NAME, TITLE, COPIES,
OPTIONS. After these are evaluated, then you will see five "shift"
commands. This will make the $6 arg shift down to $1. Now all of the
remaining args will be file names to be spooled.

Near the bottom of the script, you will see something like this:
i=1
while [ $i -le $COPIES ]
do
        for file in $files
        do
...
        done
done

In this loop is where you will put your command to output your files.
Something like "cat $file > /tmp/$OUTNAME".
You will need to decide what you want "$OUTNAME" to be and what to do if
"copies" is used or more than one file is spooled.

To help debug and test, put the following lines into the top of the
/etc/lp/interface/PRINTER script.

PR=`basename $0`
WK=/tmp
set -x
exec > ${WK}/${PR}_OUTPUT 2>&1

This will give you a new /tmp/PRINTER_OUTPUT file every time a file is
despooled.

---------------------------------------------------

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:19 EDT