[Asterisk-Users] Script to detect corrupted faxes from SpanDSP

Colin Anderson ColinA at landmarkmasterbuilder.com
Thu Dec 15 13:57:00 MST 2005


#!/bin/bash
#
#    Name: emailfax
#  Author: Colin Anderson <colina at landmarkmasterbuilder.com>
#    Desc: Script to email faxes from SpanDSP and detect if fax is corrupt
or incompatible with SpanDSP

#	These three variables must be passed to the script for it to work

FAXFILE=$1
EMAILADDRESS=$2
CALLERID=$3

#	First we convert the fax to a PDF wheter it's good, bad or whatever

/bin/nice -n 19 tiff2ps -2eaz -w 8.5 -h 11 $FAXFILE | ps2pdf - $FAXFILE.pdf

#	Then we stat the filesize of the generated PDF. A corrupt PDF
usually comes through as 422 bytes

PDFSIZE=`stat -c%s $FAXFILE.pdf 2> /dev/null`

#	If-then to email the fax if it's OK, or email the recipient to let
them know that the fax was bad,
#	and we will add it to our exception list (manually) so it will go to
a real fax machine in the future
#	If the filesize of the PDF is greater than 422 bytes send it
otherwise uh-oh.

if [ $PDFSIZE -gt 422 ]; then
mime-construct --to $EMAILADDRESS --subject "Fax from $CALLERID"
--attachment $CALLERID.pdf --type application/pdf --file $FAXFILE.pdf  
rm $FAXFILE 
rm $FAXFILE.pdf 
else
#	I use mime-consruct because I'm lazy but a piped mail command should
work just as well.
mime-construct --to $EMAILADDRESS --subject "Fax from $CALLERID failed to
receive properly - this fax number will be added to the exception list"
mime-construct --to colina at landmarkmasterbuilder.com --subject "Fax from
$CALLERID failed - fix dat shit"
rm $FAXFILE 
rm $FAXFILE.pdf 
fi



More information about the asterisk-users mailing list