The other day i got a call from a client asking if they could have a report sent by email rather than have it printed out each night. The thing was that the report was only interesting under specific conditions so it was thrown out most of the time.
After some experimentation and some useful advice I came across this useful formula.
First define a new spooler destination using the dumb interface script and /dev/null for the device. Give your new spooler destination a name - I called mine email displaying a deficit of imagination. Next, change directory to /usr/spool/lp/admins/lp/interfaces and edit email if that's what you called it. I use and like vi for editing but you can use whatever editor you like. Finally, I added a line, changing the FILTER to get the emailing done.
Immediately after this bit:
#If we are not using a filter, use the default one.
if [ -z "${FILTER}" ] then
FILTER="${LPCAT}"
fi
I added this bit:
FILTER="/usr/bin/mail -s report boopy"Where boopy is a valid user on the system. If you have sendmail or some other mail program running you can email to remote users with boopy@yourdomain.com.
Since my client wanted more than one user to receive this report by email I changed the user (boopy) to an alias and made a new alias in /usr/lib/mail/aliases. Don't forget to run newaliases if you do this, although I discovered that on Solaris it's unnecessary.
I had a little bit of help from JP Radley (jpr), which amounted to a whack on the side of the head, but it turns out he implements this with a different modification. He likes to apply this bit around the part of the script that does the actual printing: { ... } | mail -s report boopy.
{ while [ $i -le $copies ] do
for file in $files do
0<${file} eval ${FILTER} 2>&1 echo "\014\c"
done i=`expr $i + 1`
done } | mail -s report boopy
Scott McMillan dispenses with the 'dumb' interface script altogether preferring to roll his own:
shift; shift; shift; shift
files="$*"
for file in $files
do
mail -s "testing through lp" root <${file}
done
exit 0
Using any of these methods you can send email simply by invoking the spooler as you normally do, e.g., lp -demail /etc/hosts.
This works fine for plain text reports. Reports that have imbedded postscript or pcl are not candidates for emailing unless they can be converted to html, pcl or pdf. In this case you might prefer a solution where you can send your print jobs as an attachment.
Thanks to JP Radley and Scott McMillan for their ideas.
Editor's note:
See Printing FAQ also
More Articles by Dirk Hart
/DirkHart/dhemailprinter.html copyright December 2003 Dirk Hart All Rights Reserved
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.
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.
Click here to add your comments
And of course there is always the option to print to PDF: http://www.sanface.com/scolp.html
Both this article, and the PDF artcile are great examples of why I like working with *nix. I was once asked to have a report print at three different printers, in three different buildings, depending on the type of the report. With a little help from 'grep' 'cut' and 'head' this was easy. My Windows friends are still wondering how I did it :-)
- Bruce Garlock
And of course there is always the option to print to PDF: http://www.sanface.com/scolp.html
Both this article, and the PDF article are great examples of why I like working with *nix. I was once asked to have a report print at three different printers, in three different buildings, depending on the type of the report. With a little help from 'grep' 'cut' and 'head' this was easy. My Windows friends are still wondering how I did it :-)
- Bruce Garlock
And of course there is always the option to print to PDF: http://www.sanface.com/scolp.html
Both this article, and the PDF article are great examples of why I like working with *nix. I was once asked to have a report print at three different printers, in three different buildings, depending on the type of the report. With a little help from 'grep' 'cut' and 'head' this was easy. My Windows friends are still wondering how I did it :-)
- Bruce Garlock
Or ascii2pdf. Note that emailing stuff as an attachment is not within the capability of 'mail' (and ergo the solution presented above).
And of course there is always the option to print to PDF: http://www.sanface.com/scolp.html
Both this article, and the PDF article are great examples of why I like working with *nix. I was once asked to have a report print at three different printers, in three different buildings, depending on the type of the report. With a little help from 'grep' 'cut' and 'head' this was easy. My Windows friends are still wondering how I did it :-)
- Bruce Garlock
Or ascii2pdf. Note that emailing stuff as an attachment is not within the capability of 'mail' (and ergo the solution presented above).
--
I wouldn't say that "emailing stuff as an attachment is not within the capability of 'mail'". There's nothing stopping you from manually constructing a MIME compliant message with attachment and sending it with "mail".
What "mail" lacks is any assistance in that regard, but Mutt and http://aplawrence.com/Reviews/cleancodeemail.html can help you with that.
--TonyLawrence
And of course there is always the option to print to PDF: http://www.sanface.com/scolp.html
Both this article, and the PDF article are great examples of why I like working with *nix. I was once asked to have a report print at three different printers, in three different buildings, depending on the type of the report. With a little help from 'grep' 'cut' and 'head' this was easy. My Windows friends are still wondering how I did it :-)
- Bruce Garlock
Or ascii2pdf. Note that emailing stuff as an attachment is not within the capability of 'mail' (and ergo the solution presented above).
--
I wouldn't say that "emailing stuff as an attachment is not within the capability of 'mail'". There's nothing stopping you from manually constructing a MIME compliant message with attachment and sending it with "mail".
What "mail" lacks is any assistance in that regard, but Mutt and http://aplawrence.com/Reviews/cleancodeemail.html can help you with that.
--TonyLawrence
Yeah, well, since this was on a SCO system, where are the SCO binaries?
And of course there is always the option to print to PDF: http://www.sanface.com/scolp.html
Both this article, and the PDF article are great examples of why I like working with *nix. I was once asked to have a report print at three different printers, in three different buildings, depending on the type of the report. With a little help from 'grep' 'cut' and 'head' this was easy. My Windows friends are still wondering how I did it :-)
- Bruce Garlock
Or ascii2pdf. Note that emailing stuff as an attachment is not within the capability of 'mail' (and ergo the solution presented above).
--
I wouldn't say that "emailing stuff as an attachment is not within the capability of 'mail'". There's nothing stopping you from manually constructing a MIME compliant message with attachment and sending it with "mail".
What "mail" lacks is any assistance in that regard, but Mutt and http://aplawrence.com/Reviews/cleancodeemail.html can help you with that.
--TonyLawrence
Yeah, well, since this was on a SCO system, where are the SCO binaries?
--
Sco binaries for Mutt are on Skunkawre.
See http://aplawrence.com/SCOFAQ/scotec6.html#mailxmutt
--TonyLawrence
And of course there is always the option to print to PDF: http://www.sanface.com/scolp.html
Both this article, and the PDF article are great examples of why I like working with *nix. I was once asked to have a report print at three different printers, in three different buildings, depending on the type of the report. With a little help from 'grep' 'cut' and 'head' this was easy. My Windows friends are still wondering how I did it :-)
- Bruce Garlock
Or ascii2pdf. Note that emailing stuff as an attachment is not within the capability of 'mail' (and ergo the solution presented above).
--
I wouldn't say that "emailing stuff as an attachment is not within the capability of 'mail'". There's nothing stopping you from manually constructing a MIME compliant message with attachment and sending it with "mail".
What "mail" lacks is any assistance in that regard, but Mutt and http://aplawrence.com/Reviews/cleancodeemail.html can help you with that.
--TonyLawrence
Yeah, well, since this was on a SCO system, where are the SCO binaries?
--
Sco binaries for Mutt are on Skunkawre.
See http://aplawrence.com/SCOFAQ/scotec6.html#mailxmutt
--TonyLawrence
Another way to do all this:
Put Scott's script in /usr/spool/lp/model/email, modified to your needs. Then,
/usr/lib/lpadmin -p email -m email -v /dev/null
/usr/lib/accept email
/usr/lib/enable email
And of course there is always the option to print to PDF: http://www.sanface.com/scolp.html
Both this article, and the PDF article are great examples of why I like working with *nix. I was once asked to have a report print at three different printers, in three different buildings, depending on the type of the report. With a little help from 'grep' 'cut' and 'head' this was easy. My Windows friends are still wondering how I did it :-)
- Bruce Garlock
Or ascii2pdf. Note that emailing stuff as an attachment is not within the capability of 'mail' (and ergo the solution presented above).
--
I wouldn't say that "emailing stuff as an attachment is not within the capability of 'mail'". There's nothing stopping you from manually constructing a MIME compliant message with attachment and sending it with "mail".
What "mail" lacks is any assistance in that regard, but Mutt and http://aplawrence.com/Reviews/cleancodeemail.html can help you with that.
--TonyLawrence
Yeah, well, since this was on a SCO system, where are the SCO binaries?
--
Sco binaries for Mutt are on Skunkawre.
See http://aplawrence.com/SCOFAQ/scotec6.html#mailxmutt
--TonyLawrence
Another way to do all this:
Put Scott's script in /usr/spool/lp/model/email, modified to your needs. Then,
/usr/lib/lpadmin -p email -m email -v /dev/null
/usr/lib/accept email
/usr/lib/enable email
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