1833871 Members
1656 Online
110063 Solutions
New Discussion

Print file name problem

 
SOLVED
Go to solution
simon_108
Advisor

Print file name problem

Could I use "lp" command to print out the file name in the paper.

For example: I want to print out /etc/hosts, the paper should have the hosts file information and the header that has "/etc/hosts". What option of "lp" command can be used or there is no method to do that?

--Simon
3 REPLIES 3
Bill Hassell
Honored Contributor

Re: Print file name problem

Nothing in lp except a separate 'banner' page which precedes the print job. However, you can use the pr command and pipe the result to lp:

pr /etc/hosts | lp

see the man page for lots of options.


Bill Hassell, sysadmin
simon_108
Advisor

Re: Print file name problem

Hi,

Thanks your answer.

If using "pr /etc/hosts | lp" that has some trouble because I may need to do it everytime if print another file.

Do you know there has or has no any script or deamon that may enable for it?

--Simon
Bill Hassell
Honored Contributor
Solution

Re: Print file name problem

There is nothing in the lp spooler to do specialized formatting like pr. If you are good at shell scripting, you could modify each printer's script in /etc/lp/interface or /etc/lp/interface/model.orig (for HP JetDirect printers). Or create a script called prlp, something like this:

#!/usr/bin/sh
# pipe lp jobs through pr
if [ $# -lt 1 ]
then
echo "$0 requires a filename to print"
exit 1
fi
for PRINTJOB in $@
do
pr $PRINTJOB | lp
done

To sue this script, make it executable and do soemthing like this:

export LPDEST=myprinter
prlp /etc/hosts /etc/profile /etc/fstab


Now this is fairly simple--no options for pr and no options for lp. You can set the printer to use with LPDEST outside the script, or make the printer the first parameter and the printjob(s) the second parameter. Lots of possibilities, just look at the man page for pr.


Bill Hassell, sysadmin