Problem
I want to be able to print to a file on my SCO OpenServer 5 system. I use an application that contains embedded lp(C) print commands that usually sends output to a printer. However, I want to be able to specify a printer name, but actually direct the output into a file.
Solution
(a) In the following example, a simple printer is configured and the interface file it uses is altered to direct its output to files in the "/tmp" directory.
As the "root" user, start the "scoadmin(ADM)" utility and choose:
Printers, Printer Manager, Printer, Add LocalName: scoprint
Description: file printer
Model: dumb
Device: /dev/tty2aIn this example, there is no physical printer at COM2. The printer is enabled and set up:
# lpstat -a
scoprint accepting requests since 03:44:51 PM Mon 27 Mar 2The associated interface file in this case is in the file
"/var/spool/lp/admins/lp/interfaces/scoprint". This is a copy of
the "dumb" interface file kept in the "/var/spool/lp/model"
directory. Make a backup of this file and insert the following
code, replacing what's currently there:< ---- cut here ---- >:#Set up some global variables.
: ${SPOOLDIR:=/usr/spool/lp}
: ${LOCALPATH:=${SPOOLDIR}/bin}#Set up the default filter.
if [ -x "${LOCALPATH}/lp.cat" ]
then
LPCAT="${LOCALPATH}/lp.cat 0"
else
LPCAT="cat"
fi#If we are not using a filter, use the default one.
if [ -z "${FILTER}" ]
then
FILTER="${LPCAT}"
fiif [ -x "${LOCALPATH}/drain.output" ]
then
DRAIN="${LOCALPATH}/drain.output 1"
else
DRAIN=
finobanner="no"if [ -z "${BANNERS}" ]
then
nhead=1
else
nhead=${BANNERS}
fifor i in $5
do
case "${i}" in nobanner )
nobanner="yes"
;;
esac
donerequest=$1
copies=$4
saveargs="$*"shift; shift; shift; shift; shift
files="$*"
i=1
while [ $i -le $copies ]
do
echo Print request ID S1 > /tmp/${request}
echo Created `date` >> /tmp/${request}
id >> /tmp/${request}
echo "Arguments passed to interface :-" >> /tmp/${request}
echo $saveargs >> /tmp/${request}
env >> /tmp/${request}
echo "Print data follows..." >> /tmp/${request}
echo >> /tmp/${request} for file in $files
do
cat ${file} >> /tmp/${request}
done
i=`expr $i + 1`
doneexit 0< ---- cut here ---- >Make the permissions of the file as follows:
# ls -al scoprint
-rwxrwxr-x 1 lp lp 1805 Mar 27 16:18 scoprintA file can now be sent to the "scoprint" printer and the output should appear in the "/tmp/" area, for example:
# lp -d scoprint /etc/motd
request id is scoprint-523 (1 file)# ls -al /tmp/scoprint*
-rw-rw---- 1 root lp 1682 Mar 27 16:19 /tmp/scoprint-523# pg /tmp/scoprint-523
Print request ID S1
Created 04:19:03 PM Mon 27 Mar 2000 BST
uid=0(root) gid=18(lp) groups=3(sys),0(root),1(other)
Arguments passed to interface :-
scoprint-523 root 1 stty='9600 cs8 -parenb' /etc/motd
BANNERS=1
HZ=100
LC_MESSAGES=en_GB.ISO8859-1
LC_TIME=en_GB.ISO8859-1
LEVEL=wait
LPDEBUG=0
PATH=/bin:/etc:/usr/bin:/tcb/bin
PS1=#
SPOOLER_KEY=967005361
SPOOLER_SLOT=78
TERM=unknown
TZ=GMT0BST,M3.5.0/1,M10.5.0/1
...
the contents of "/etc/motd" follows here .......
....(b) Another method to print to a file is as follows:
As "root", create a file, for example "/myprintfile":
# cat >myprintfile
# ls -al myprintfile
-rw-r--r-- 1 root sys 0 Apr 10 09:17 myprintfileChange its owner and group permissions to "lp":
# chown lp:lp myprintfile
# ls -al myprintfile
-rw-r--r-- 1 lp lp 0 Apr 10 09:17 myprintfileAs in (a) above, start SCOadmin and create a local printer, with the following parameters:
Name: fileprint
Description: Print to file
Model: Standard
Device: /myprintfileCheck that it is set up:# lpstat -a
...
fileprint accepting requests since 09:24:15 AM Mon 10 Apr 2Print a file: # lp -d fileprint /etc/motd
request id is fileprint-546 (1 file)The file prints into the file "myprintfile" including its banner page. Subsequent prints are appended to the file.
The configuration file with the "/myprintfile" device can be seen in the file "/var/spool/lp/admins/lp/printers/fileprint/ configuration".
(c) You can also print to a console multiscreen, for example, "tty12".
Log in to the multiscreen (using <Ctrl><Alt><F12>) and verify the port number using "tty(C)". Log out and then disable the login using:
# disable /dev/tty12
/etc/inittab updated
/etc/conf/cf.d/init.base updatedThe device must be writable by lp:
# ls -al /dev/tty12
crw------- 1 bin terminal 0, 11 Apr 10 09:36 /dev/tty12
# ls -al /dev/tty12
crwx---rw- 1 bin terminal 0, 11 Apr 10 09:36 /dev/tty12We can also use the "lpadmin(ADM)" command, for which SCOadmin provides a front end, to add the printer:
# /usr/lib/lpadmin -p tty12pr -b 0 -D "tty printer" -m
standard -v /dev/tty12
# accept tty12pr
# enable tty12prThen print the file:# lp -d tty12pr /etc/profileAn alternate method to create a simple file printer:
# mkdir /var/lp
# touch /var/lp/fileptr
# chown lp:lp /var/lp /var/lp/fileptr
# chmod 600 /var/lp/fileptr
# /usr/lib/lpadmin -p fileptr -v /var/lp/fileptr
# enable fileptr
# accept fileptr