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.


Hate these ads?

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.


Technorati tags:    

Comments /SCOFAQ/FAQ_scotec7printtofile.html


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



Add your comments

ad

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


LOD Communications, Inc.

Views for this page
Today This Week This Month This Year  Overall
135100742 3,501

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

pavatar.jpg
More:
       - Blog
       - FAQ
       - Printing




Unix/Linux Consultants


http://thatitguy.com Business networking servers, Linux and Unix experts. In business since 1997! Windows and Exchange to Samba and Scalix migration experts.


http://www.vss3.com SCO/Caldera OpenServer, Unixware & Linux. Tarantella & Non-stop Clustering


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


Twitter
  • May 16 08:08
    My tea tastes like chlorine. I dumped it out, tried just the teawater. That's fine. Why does my tea taste like chlorine?
  • May 16 07:31
    Have stayed away from the gym most of the week - my neck is feeling better.




card_image








Change Congress

Related Posts