(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



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 Desktop or Openserver.

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.

Printing FAQ

How can I make a printer that will print to a file?

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.




Click here to add your comments





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


Hi

Found this at Sco Support at this URL
http://wdb1.sco.com/kb/showta?taid=110966&qid=474749425&sid=2104329929&pgnum=1
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: Subject: Zombie stays   anonymous


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



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

gravatar
Be specific. Exactly what are you seeing?



Thu Jul 10 20:50:32 2008: Subject:   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".

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

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. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - Blog
       - FAQ
       - Printing


Unix/Linux Consultants

Skills Tests

Guest Post Here








card_image






My Favorites

Change Congress