#	Sample script to show how to take files from an "outgoing"
#	directory whose names follow the convention of "nickname.txt"
#	and execute "faxsend -c nickname nickname.txt".
#	After the file has been successfully queued for transmission,
#	it is renamed to nickname.old.  
#
OUTGOING=/usr/spool/reports		# Or wherever you store the files
#
#	We're going to do all our work in $OUTGOING, so 'cd' there
#
cd $OUTGOING
#
#	Generate a list of files to be sent using 'find'
#	and pipe them to a shell read loop to process each FILENAME
#
find . -name '*.txt' -print |
	while read FILENAME
	do
		#	Use 'basename' to get just the nickname portion
		NICKNAME=`basename $FILENAME .txt`
		#	Now run faxsend, no cover sheet, and no interactive
		#	confirmation.  Toss the output.
		faxsend -c $NICKNAME $FILENAME >/dev/null 2>&1
		#	Check return code.  If successful, rename the file
		if [ $? = 0 ]
		then
			mv $NICKNAME.txt $NICKNAME.old
		else
			if [ -s $FILENAME ]
			then
				echo "Couldn't find $NICKNAME in faxphone"
			else
				echo "$FILENAME was zero length -- deleted"
				rm $FILENAME
			fi
		fi
	done
