[Samba] Print Job Notification

Joel Hammer Joel at HammersHome.com
Tue Jun 25 20:51:34 GMT 2002

Ok. This is one way to do what you want. I haven't edited this to make
it plainer since you ought to do some of this work, too.  Basically,
just put && Success command || Failure command after your print command
in your filter. This filter uses pstotext, which just converts PDP or
ps files to plain text and is very good but may not be included with
your distribution.  It is better than gs. It is out on the internet,
somewhere.  The print filter below simply takes a postscript,
PDP file, or a plain text file and outputs a plain text file to
whatever output device is specified in /etc/printcap. In this case,
lp=/var/spool/lpd/text/textfile. The printcap that goes with this is:


This print filter is designed to enable me to print things off the
internet and get a plain text file to include in email. The final text
file will wind up in /tmp/textprint. It relies on shell variables which
you will see in file junk and shellvalues after the print job is done.
Keep in mind that when invoked by lpr, this script will use the file to
print as standard input and the destination lp in printcap as standard
output. Therefore commands like:

 set | sed -n "s/^l//p" | xargs file

send output to the output device, in this case outfile defined below.

And, you have to include the full pathname for programs like
mail since the user daemon may not have such programs in its path.
Note: This is not a polished product. I am a total amateur. 

cat < /dev/null > junk
set > junk
outfile=`set | sed -n "s/.*:lp=//p"`
echo This is the start >> junk
echo This is the outfile $outfile >> junk
cat < /dev/null > $outfile
set > shellvalues
Job=`set | sed -n "s/^N//p"`
#============Print Post Script================
a=`set | sed -n "s/^l//p" | xargs file | grep PostScript`
echo $a This is a PostScript file > junkname
[ -z "$a" ] || {
/usr/local/bin/pstotext && echo "Job $Job Done" | /bin/mail -s "PrintingDone" jlh  || echo "Job $Job Failed" | /bin/mail -s "Printing Failed" jlh
cp -a $outfile $readfile
chmod 777 $readfile
exit 0
#===========Print PDF==========================
a=`set | sed -n "s/^l//p" | xargs file | grep PDF`
echo $a This is a PDF file > junkname
[ -z "$a" ] || {
#  Remember that converting PDF to text requires random
#    access and so pstotext cannot read the file from std in
cat > /tmp/junkprint
/usr/local/bin/pstotext /tmp/junkprint -output -  && echo "Job $Job Done" | /bin/mail -s "Printing Message" jlh || echo "Job $Job Failed" | /bin/mail -s "Printing Failed" jlh
cp -a $outfile $readfile
chmod 777 $readfile
exit 0
#============Print Text========================
a=`set | sed -n "s/^l//p" | xargs file | grep text `
[ -z "$a" ] || {
cp -a $outfile $readfile
chmod 777 $readfile
exit 0
#============Bail out=====================
echo invalid file type of
set | sed -n "s/^l//p" | xargs file
cp -a $outfile $readfile
exit 0 

If you wonder at the exit 0 statements, I THINK that the print filter has to
exit with status 0, othewise LPRng thinks things have gone bad and will

On Sat, Jun 22, 2002 at 03:31:28PM -0500, Chad Edwards wrote:
> Can anyone suggest a way to have a notification after a print job has
> completed. I currently have this as my print command:
> lpr -r -P%p %s; csh -c 'echo \"%J has started printing on %S\" |
> /usr/bin/smbclient -U %L -M %m -I %I' &
> It kind of does what I want, but notice that the message says that "Job has
> STARTED printing on Printer". This is because with this command the message
> is sent after the lpr command is executed and not when the job is actually
> done. I would really prefer the message be sent when the job is done, not
> when it is starting.
> I saw an old message in the archives suggesting a wrapper for the print
> command that would keep checking the print queue to see when the job was
> done and then send the message. This sounds like it would work, but I don't
> have a clue how to write the wrapper to check the queue.
> Any help in this matter would be appreciated.
> Chad Edwards
> Samba Newbie
> -- 
> To unsubscribe from this list go to the following URL and read the
> instructions:  http://lists.samba.org/mailman/listinfo/samba

More information about the samba mailing list