: !/bin/sh ######################################################################## # T21BATCHNAME wbfailedmail.t21batch # T21BATCHDESC Bilmax21 Web Billing Falled Emails Report # ALLOWBLANKDATES false # CUSTOMDESC # CUSTOMDEF # T21BATCHVAR1DESC # T21BATCHVAR1VALU # T21BATCHVAR2DESC # T21BATCHVAR2VALU # T21BATCHVAR3DESC # T21BATCHVAR3VALU # T21BATCHVAR4DESC # T21BATCHVAR4VALU # T21BATCHVAR5DESC # T21BATCHVAR5VALU # T21BATCHENDARGS ######################################################################## #echo "\$@=[$@] - Hit Enter" #read x progname=$0 tmpfile=/tmp/wbfailedmail_$$ ################################################################# lastdayinmonth() # Returns the last day in month, Inputs: $1=mm $2=yyyy { cal $1 $2 | awk '{ if ( NF > 0 ) x=$NF } END { print x }' } ################################################################# # MAIN ######################################################################## # handle arg list SDATE=$1; EDATE=$2; STIME=$3; ETIME=$4 if [ -n "$5" ]; then SITEID=$5 fi ######################################################################## # get missing args #if [ -z "$SITEID" ]; then # echo "Enter siteid (Enter for ALL):\c"; read SITEID #fi #if [ -z "$SITEID" ]; then # SITEID="ALL" #fi #if [ -z "$SDATE" ]; then # echo "Enter start date:\c"; read SDATE #fi #if [ -z "$EDATE" ]; then # echo "Enter end date:\c"; read EDATE #fi #if [ -z "$STIME" ]; then # echo "Enter start time HH:MM:\c"; read STIME #fi #if [ -z "$ETIME" ]; then # echo "Enter end time HH:MM:\c"; read ETIME #fi ######################################################################## email_file() { for emailaddr in $emaillist do # Force mail to pass DATE as GMT TZ=''; export TZ ( if [ -n "$attfiles" ]; then echo "Please Find Attached Information " fi for extraf in $extratxtfiles do if [ -n "$extraf" ]; then cat $extraf echo " " fi done if [ -n "$attfiles" ]; then for attf in $attfiles do uuencode $attf `basename $attf` done fi ) | mail -s "$subject" $emailaddr #) >em_${fnameprefix}tot_${fnamepostfix}.eml done } ######################################################################## # send file to user exec 1>$tmpfile 2>&1 echo "" echo " Bilmax21 Web Billing Failed Emails `date`" echo "" echo " Date From: $SDATE To: $EDATE" echo "" ########## egrep "Failed mail|To:|Date:" /usr/spool/mail/bilmax21 | awk \ -v "sdate=$SDATE" -v "edate=$EDATE" ' ################################################ function dosql(sql) { #print "dosql(", sql, ")" "echo $$" | getline uniqsqlid uniqsqlid += sqlcounter sqlcounter += 1 ##print "uniqsqlid = ", uniqsqlid tmpsqlout = "/tmp/sqlout" uniqsqlid ##print "tmpsqlout = ", tmpsqlout #sqlproc = "runisql 2>&1" sqlproc = "runisql 1>/dev/null 2>&1" printf( "unload to %s %s;", tmpsqlout, sql) | sqlproc close sqlproc return tmpsqlout } function closesql(sqlf) { ##print "closesql(", sqlf, ")" close sqlf system("rm -f " sqlf) } ################################################ function DBG() { } { #print $0; #print "1=[" $1 "]" " 2=[" $2 "]" " 3=[" $3 "]" if ( $1 == "Subject:" ) { if ( $2 == "Failed" && $3 == "mail" ) infailed = 1; else infailed = 0; #print "infailed=" infailed next; } if ( infailed ) { if ( $1 == "Date:" ) { # "Date: Sat, 6 Jan 2007 3:30:02 +0000 (GMT)" fdate = $0 fwday = $2 fdd = $3 fmmm = $4 fyyyy = $5 femdate = fwday " " fdd " " fmmm " " fyyyy #select DATE("Sat, 6 Jan 2007") #from ovhtype where rowid = 1; sql1 = "select DATE(\"" femdate "\") inperiod from ovhtype where rowid=1 and DATE(\"" femdate "\") between \"" sdate "\" and \"" edate "\"" #print "sql1 = [" sql1 "]" sql1id = dosql( sql1 ); while ((getline aline < sql1id) > 0) { gsub(/\\\|/, ";",aline) split(aline, sql1arr, "|") inperiod = sql1arr[1] break } closesql(sql1id) #DBG(); print "inperiod = " inperiod next; } if ( $1 == "To:" && $2 != "bilmax21@telmax.curtin.edu.au" && inperiod != "" ) { #print "Failed [" fdate "]" " to " $2 #print " Failed Email on " inperiod " to " $2 | "sort -u"; print " Failed Email to " $2 | "sort -u"; } } } ' ########## echo "" echo " End." # send output to user #cat $tmpfile | pr_rep system wbfailedmail_ attfiles="" extratxtfiles="$tmpfile" subject="Failed Bilmax21 Emails" emaillist="bilmax21 support@transmit.com.au d.pim@curtin.edu.au w.carr@curtin.edu.au" #emaillist="telmax21" email_file rm -f $tmpfile exit 0