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.
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 do cat /dev/sharedprint | /usr/local/bin/sharedprint done # cat /usr/bin/startpersonal mknod /dev/persprint p chmod 777 /dev/persprint while true do cat /dev/persprint | /usr/local/bin/persprint done
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 ] then /bin/mkdir PRINTED /bin/chown $user PRINTED /bin/chmod 755 PRINTED fi cd PRINTED DATE=`/bin/date +%y%m%d%H%M%S` /bin/touch $DATE /bin/chown $user $DATE while read stuff do 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 ] then /bin/mkdir PRINTED /bin/chown $user PRINTED /bin/chmod 755 PRINTED fi cd PRINTED DATE=`/bin/date +%y%m%d%H%M%S` DATE=$user.$DATE /bin/touch $DATE /bin/chown $user $DATE while read stuff do 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 44c44 < nobanner="no" --- > nobanner="yes" 61a62 > user=`grep "^$2:" /etc/passwd | line | cut -d: -f1` 91c92 < echo "\014\c" --- > echo "$user" 100d100 < 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.
More Articles by Tony Lawrence © 2013-07-18 Tony Lawrence