# # (SCO Unix) How do I make a printer that will print to a file?
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.

Some material is very old and may be incorrect today

© June 2004 Tony Lawrence

SCO Unix/System V Printing FAQ

This article is from a FAQ concerning SCO operating systems. While some of the information may be applicable to any OS, or any Unix or Linux OS, it may be specific to SCO Xenix, Open There is lots of Linux, Mac OS X and general Unix info elsewhere on this site: Search this site is the best way to find anything.

How can I make a SCO Unix/System V printer that will print to a file?

For CUPS (Linux. Mac) printing, see CUPS (Common Unix Printing System) print to file - the hard way!

SCO (without CUPS): Setting up a printer that will print to a file can be useful for any number of reasons. Here we set up two printers; one that prints to files in the user's home directory, and another that prints to a shared common area.

The first problem is that we need a root process to do the writing. We could do that with sudo or asroot (SCO), but I chose to do it with two scripts that read named pipes. These scripts are run at startup:

 # cat /usr/bin/startshared
 mknod /dev/sharedprint p
 chmod 777 /dev/sharedprint
 while true
 cat /dev/sharedprint | /usr/local/bin/sharedprint
 # cat /usr/bin/startpersonal
 mknod /dev/persprint p
 chmod 777 /dev/persprint
 while true
 cat /dev/persprint | /usr/local/bin/persprint

The printers will send their data to the appropriate devices, and in turn the data will be passed to the scripts that actually do the writing. We've modified the printer scripts to send the user name as the first line of the data:

 # cat /usr/local/bin/persprint
 read user
 cd /usr/$user || cd /
 if [ ! -d PRINTED ]
   /bin/mkdir PRINTED
   /bin/chown $user PRINTED
   /bin/chmod 755 PRINTED
 DATE=`/bin/date +%y%m%d%H%M%S`
 /bin/touch $DATE
 /bin/chown $user $DATE
 while read stuff
 echo $stuff
 done > $DATE
 /bin/chmod 664 $DATE

This was on a SCO system, with user home directories in /usr; we could make a more complex script that would extract the home directory from /etc/passwd. The file name is just a simple date stamp. For the shared printer, we include the user name:

 # cat  /usr/local/bin/sharedprint
 read user
 cd /usr/shared/FORMS
 if [ ! -d PRINTED ]
   /bin/mkdir PRINTED
   /bin/chown $user PRINTED
   /bin/chmod 755 PRINTED
 DATE=`/bin/date +%y%m%d%H%M%S`
 /bin/touch $DATE
 /bin/chown $user $DATE
 while read stuff
 echo $stuff
 done > $DATE
 /bin/chmod 666 $DATE

The printer needs to send us user information. In this case, we modified a copy of SCO's "dumb" interface script:

 # diff dumb personal
 < nobanner="no"
 > nobanner="yes"
 > user=`grep "^$2:" /etc/passwd | line | cut -d: -f1`
 < echo "\014\c"
 > echo "$user"
 <               echo "\014\c"

but we could also have just written a more complex parsing that could have extracted this from banner pages.

I added the printers like this:

 /usr/lib/lpadmin -p personal -m personal -v /dev/persprint
 /usr/lib/accept personal
 enable personal 

These same concepts will work with Linux or any other Unix-like OS. The only real requirement is that the print job include user info, and even that isn't necessary if you only want the shared version. Just point the printer at the named pipe instead of /dev/lp0 or anywhere else.

See also SCO TA #110966

If you found something useful today, please consider a small donation.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> (SCO Unix) How do I make a printer that will print to a file?


Inexpensive and informative Apple related e-books:

El Capitan: A Take Control Crash Course

Photos for Mac: A Take Control Crash Course

Take Control of Upgrading to El Capitan

Take Control of Automating Your Mac

Photos: A Take Control Crash Course

More Articles by © Tony Lawrence

Tue Jul 5 09:06:07 2005: 750   anonymous


Found this at Sco Support at this URL
It looks like a simple solution.

(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".

Thu Jul 10 18:01:59 2008: 4411   anonymous

For some reason, after each print process, a zombie stays hanging around. Any ideas?

Thu Jul 10 18:19:39 2008: 4412   TonyLawrence

Be specific. Exactly what are you seeing?

Thu Jul 10 20:50:32 2008: 4413   anonymous

Hard to say at the moment; after "printing" to file using your suggestion, I see one more "Defunct" process in the list of processes. No idea what that process was, though, it just reads "Defunct".


Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

If we define Futurism as an exploration beyond accepted limits, then the nature of limiting systems becomes the first object of exploration. (Frank Herbert)

Linux posts

Troubleshooting posts

This post tagged:




Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode