Received fax report for Hylafax using GAWK.

January 21, 2009 at 3:17 pm (coding, linux, TechTips) (, , , )

I like using the open source fax server software Hylafax for deploying fax services to a network.

One of the great things about using Hylafax for fax services, is the great flexibility you get.  Lately, one of my users requested that I create a report that could be automatically sent to her group daily.  This report was to show all faxes that were sent to their inbound fax number during the previous day.  In particular they wanted to be able to look for any faxes that someone had tried to send to them that failed for some reason.

I decied to use GAWK in order to parse the transfer log and create the resulting report.  Then, I wrapped this gawk script in a little bash script to add a little functionality.  Finally, this bash script was added to cron.daily, so as to produce the report and email it on a daily basis.

Simply change YOURFAXNUMBERHERE to be what receiving fax number you want to report on.  Finally you’ll want to pipe the output to mail if you want it to get emailed automatically.  I’m sure there are numerous better ways to make the format better, etc.  However, this is my quick script and it works perfectly for my needs.  Let me know if you find it useful.

#!/bin/bash

#####################################
# faxrecreport.sh
#
# Written by: Jason Fenner
#
# V 1.0
#
# 01/21/2009
#
# This report will print out all
# recv’d faxes for a certain inbound
# fax number that was received
# in the last 24 hour period.
#
####################################

DATEPERIOD=`date –date=yesterday +%D`
FAXNUMBER=”YOURFAXNUMBERHERE”

echo “Fax Receive Report”
echo
echo “——————”
echo “Fax Number: $FAXNUMBER”
echo “24 Hour Period for: $DATEPERIOD”
echo “——————”
echo
echo

awk -F’\t’ ‘BEGIN{ “date –date=yesterday +%D ” | \
getline dateVal; printf(“%15s%30s%15s%7s %8s%50s %12s\n”,”Date”,”Name”,”CallerID”,”Pages”,”Duration”,”Error”,”Ref”); \
for (x=1; x<=140; ++x) {printf( “%s” , “-” ) } \
print “” }
($2 ~ /RECV/ && $16 ~ /YOURFAXNUMBERHERE/ && $1 ~ dateVal) \
{gsub(/\”/,””); if ($14 == “”) $14 = “None”; \
if ($15 == “”) $15 = “Not Received”; \
printf(“%15s%30s%15s%7s %8s%50s %12s\n”, $1,$9,$15,$11,$13,$14,$3)
}

END{ for (x=1; x<=140; ++x) {printf( “%s” , “-” ) } \
print “” }’ /var/spool/hylafax/etc/xferfaxlog

Permalink 3 Comments