Technical article 110966

How can I configure OpenServer to print to a file?

OpenServer 6.0.0OpenServer 5.0.4OpenServer 5.0.5OpenServer 5.0.6OpenServer 5.0.7

Written · Last revised

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 Local
Name:           scoprint
Description:    file printer
Model:          dumb
Device:         /dev/tty2a

In 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 2
The 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}"
fi
if [ -x "${LOCALPATH}/drain.output" ]
then
        DRAIN="${LOCALPATH}/drain.output 1"
else
        DRAIN=
fi
nobanner="no"
if [ -z "${BANNERS}" ]
then
        nhead=1
else
        nhead=${BANNERS}
fi
for i in $5
do
        case "${i}" in
        nobanner )
                nobanner="yes"
                ;;
        esac
done
request=$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`
done
exit 0
< ---- cut here ---- >

Make the permissions of the file as follows:

# ls -al scoprint
-rwxrwxr-x   1 lp       lp          1805 Mar 27 16:18 scoprint

A 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 myprintfile

Change 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 myprintfile

As in (a) above, start SCOadmin and create a local printer, with the following parameters:

Name:           fileprint
Description:    Print to file
Model:          Standard
Device:         /myprintfile
Check that it is set up:
# lpstat -a
...
fileprint accepting requests since 09:24:15 AM Mon 10 Apr 2
Print 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 updated

The 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/tty12

We 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 tty12pr
Then print the file:
# lp -d tty12pr /etc/profile
An 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

From the Xinuos technical article database, record 110966. Reproduced with permission. The original is at www.sco.com/ta/110966, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.