: !bin/sh ######################################################################## # T21BATCHNAME rseedistid # T21BATCHDESC Send/Resend Email Web Reports # ALLOWBLANKDATES false # CUSTOMDESC Enter Override email address # CUSTOMDEF # T21BATCHVAR1DESC Do Even If Already Sent before or Dont Send (Y/N) # T21BATCHVAR1VALU N # T21BATCHVAR2DESC Enter distid ID to email, or list file (Blank for ALL) # T21BATCHVAR2VALU xxxx # T21BATCHVAR3DESC Enter number of emails before pausing (0 no pause) # T21BATCHVAR3VALU DEFAULT # T21BATCHVAR4DESC Enter pause time in minutes # T21BATCHVAR4VALU DEFAULT # T21BATCHVAR5DESC Do PERSONAL # T21BATCHVAR5VALU N # T21BATCHENDARGS ######################################################################## #workdir="/u/catcom/wb/ex4" # Testing workdir="/u/catcom/wb/ex4_tst" #workdir="." . /u/catcom/catcom_vars . /u/catcom/scripts/stdsqlheader # get todays date today=`date "+%d/%m/%Y"` # for when invoked from wbt_dorelease.cgi HOME="/u/catcom/wb" export HOME LOGNAME="bilmax21" export LOGNAME umask 002 # cache local copy of tPerson copytPerson #----------------------------------------------------------------- SDATE=$1; EDATE=$2; STIME=$3; ETIME=$4; SITEID=$5 #DEFMAXKSIZE="6000" DEFMAXKSIZE="8100" if [ -z "$WBEMAILMAXKSIZE" ]; then maxKsize="$DEFMAXKSIZE" else maxKsize="$WBEMAILMAXKSIZE" fi # custom param to specifiy only one distid to email # override email addres if [ -n "$6" ]; then override_email="$6" else override_email="" fi # send even if Already sent if [ "$override_email" != "" -o "$T21BATCHVAR1VALU" = "y" -o "$T21BATCHVAR1VALU" = "Y" ]; then ALWAYS_SEND="Y" else ALWAYS_SEND="N" fi # only one distid, or distid list file name to email onlythisdistid="" distidlistfile="" if [ "$T21BATCHVAR2VALU" != "" ]; then # check if its a list file if [ -f "$T21BATCHVAR2VALU" ]; then distidlistfile="$T21BATCHVAR2VALU" else onlythisdistid="$T21BATCHVAR2VALU" fi fi if [ "$onlythisdistid" = "ALL" ]; then onlythisdistid="" distidlistfile="" fi # specifiy email count before pause if [ "$T21BATCHVAR3VALU" != "" ]; then emailsbeforepause="$T21BATCHVAR3VALU" else emailsbeforepause="0" fi if [ "$emailsbeforepause" = "ALL" ]; then emailsbeforepause="0" fi if [ "$emailsbeforepause" = "DEFAULT" ]; then emailsbeforepause="$WBEMAILSBEFOREPAUSE" fi # specifiy pause in minutes if [ "$T21BATCHVAR4VALU" != "" ]; then pauseinminutes="$T21BATCHVAR4VALU" else pauseinminutes="0" fi if [ "$pauseinminutes" = "ALL" ]; then pauseinminutes="0" fi if [ "$pauseinminutes" = "DEFAULT" ]; then pauseinminutes="$WBEMAILPAUSEINMINUTES" fi # do PERSONAL distid's if [ "$T21BATCHVAR5VALU" = "y" -o "$T21BATCHVAR5VALU" = "Y" ]; then DO_PERSONAL="Y" else DO_PERSONAL="N" fi ############ ## Testing #SDATE="01/11/2009" #EDATE="30/11/2009" #SITEID="ALL" #ALWAYS_SEND="Y" ###onlythisdistid="1266" #onlythisdistid="4380" #distidlistfile="/u/catcom/wb/ex4_tst/reldistidlist.csv" #override_email="demo" override_email="rod@transmit.com.au" #override_email="support@transmit.com.au" #emailsbeforepause="$WBEMAILSBEFOREPAUSE" #pauseinminutes="$WBEMAILPAUSEINMINUTES" #DO_PERSONAL="Y" #----------------------------------------------------------------- email_file() { echo "email_file() attfiles=[$attfiles] extratxtfiles=[$extratxtfiles] subject=[$subject] emaillist=[$emaillist]" for emailaddr in $emaillist do realemail=$emailaddr echo "realemail=[$realemail]" if [ "$override_email" != "" ]; then emailaddr=$override_email fi echo "Sending to emailaddr=[$emailaddr]" ## Testing #echo "WOULDBE Sending to emailaddr=[$emailaddr]" #return # Force mail to pass DATE as GMT TZ=''; export TZ ( #echo "Please Find Attached Information " if [ -n "$toptxtfile" ]; then cat $toptxtfile echo " " fi if [ -n "$extra_emtxt" ]; then echo "$extra_emtxt" echo "############################################### " echo " " fi for extraf in $extratxtfiles do if [ -n "$extraf" ]; then cat $extraf echo " " fi done if [ -n "$bottomtxtfile" ]; then cat $bottomtxtfile echo " " fi for attf in $attfiles do uuencode $attf `basename $attf` ## Testing #echo "" #echo "-------------------------------------" #echo "Email for userid=$userid" #echo " recordno=$wbdconf_recordno" #echo " distid=$wbdconf_distid" #echo " fileattachment=$attf" #echo " zipKsize=$zipKsize" #echo "-------------------------------------" #echo "" done ) | tr -d "\015" | mail -s "$subject" $emailaddr #) >../em_${userid}_${distid}_${monthdir}.eml done } ########################## do_build_offline() { echo "Do build offline for $distiddir to $email" echo "" echo "size under topdat/$distiddir" du -k topdat/$distiddir | awk -v "distiddir=topdat/$distiddir" '{if ($2 == distiddir) print $0;}' echo "" echo "contents of topdat/$distiddir" ls "topdat/$distiddir" echo "-------" echo "" #echo "topdat/$fnamelistfile ..." #cat topdat/$fnamelistfile #echo "-------" #echo "" offlinedir="offline" offlinetopdat="$userid" # create image in offline dir mkdir -p $offlinedir/$offlinetopdat/$billperiod/data echo "create distiddir symlink" rm -f "$offlinedir/$offlinetopdat/$billperiod/$distid" ln -s "../../../topdat/$billperiod/$distid" "$offlinedir/$offlinetopdat/$billperiod/$distid" echo "" echo "create distidfile symlink" # eg. neil.roberts@yarratrams.com.au_Nov_2012.txt distidfile="${userid}_${billperiod}.txt" rm -f "$offlinedir/$offlinetodat/$billperiod/$distidfile" ln -s "../../../topdat/$billperiod/$distidfile" "$offlinedir/$offlinetopdat/$billperiod/$distidfile" echo "" echo "create common symlink" rm -f "$offlinedir/$offlinetopdat/common" ln -s "../../comdat/common_offline" "$offlinedir/$offlinetopdat/common" echo "" echo "create doc symlink" rm -f "$offlinedir/$offlinetopdat/doc" ln -s "../../topdat/doc" "$offlinedir/$offlinetopdat/doc" echo "" # conf has didyouknow and mobile personal user data echo "create conf symlinks" #ln -s "../../topdat/conf" "$offlinedir/$offlinetopdat/conf" echo "only link didyouknow file" mkdir -p "$offlinedir/$offlinetopdat/conf" rm -f "$offlinedir/$offlinetopdat/conf/didyouknow.txt" ln -s "../../../topdat/conf/didyouknow.txt" "$offlinedir/$offlinetopdat/conf/didyouknow.txt" echo "" echo "copy and rename user index html file" rm -f "$offlinedir/$offlinetopdat/$userhtmlfile" cp img/xuser.html "$offlinedir/$offlinetopdat/$userhtmlfile" echo "" # handle wbttop.csv echo "handle wbttop.csv" # header #User List,November 2012,SDATE,EDATE,UserID_DESC,UserID,DistID_DESC,DistID,BDMethod,BDType,RealeaseDate,RegenDate,LastSentDate #grep 3025 topdat/Nov_2012/data/wbttop.csv #,,,,NEIL ROBERTS,neil.roberts@yarratrams.com.au,Bilmax21 Cost Centre Reports,3025,WEB,INVOICE_PDF,30-11-2012,,30-11-2012 #,,,,NEIL ROBERTS,neil.roberts@yarratrams.com.au,Management Reports,mng3025,WEB,MANAGEMENT,30-11-2012,,30-11-2012 # copy entries for userid, (excluding personal) rm -f "$offlinedir/$offlinetopdat/$billperiod/data/wbttop.csv" egrep "^User List,|,${userid}," topdat/$billperiod/data/wbttop.csv |\ grep -v ",PERSONAL," > "$offlinedir/$offlinetopdat/$billperiod/data/wbttop.csv" echo "---- $offlinedir/$offlinetopdat/data/wbttop.csv ----" cat "$offlinedir/$offlinetopdat/$billperiod/data/wbttop.csv" echo "---------------------------" echo "" echo "handle networkaverage.csv" # should only copy relevalnt VNUMs, and header #,,,,VicTrack Rent and Calls - Calls,1,VNUM_10001385,3,428,79028,77.46,25.82 echo "copy VNUMs from topdat/$billperiod/data/networkaverage.csv" egpat="${vnumlist}^Network Average" echo "egpat=[$egpat]" echo "-----" egrep "$egpat" "topdat/$billperiod/data/networkaverage.csv" echo "-----" rm -f "$offlineir/$offlinetopdat/$billperiod/data/networkaverage.csv" egrep "$egpat" "topdat/$billperiod/data/networkaverage.csv" > "$offlinedir/$offlinetopdat/$billperiod/data/networkaverage.csv" echo "" } #---------------------- do_email_zip() { echo "Do email zip for $distiddir to $email" echo "" echo "size under topdat/$distiddir" du -k topdat/$distiddir | awk -v "distiddir=topdat/$distiddir" '{if ($2 == distiddir) print $0;}' echo "" echo "contents of topdat/$distiddir" ls "topdat/$distiddir" echo "-------" echo "" echo "topdat/$fnamelistfile ..." cat topdat/$fnamelistfile echo "-------" echo "" # create image in zipdat dir rm -f -r zipdat/topdat mkdir -p zipdat/topdat mkdir -p zipdat/topdat/$billperiod/data ## copy distid fnamelist files #cat topdat/$fnamelistfile | cpio -pvdum zipdat 2>&1 1>/dev/null # handle distid fnamelist files cat topdat/$fnamelistfile | \ while read user_fname do # test for billperiod/data to do user symlinks instead # and handle wbttop.csv if expr match "$user_fname" "^topdat/$billperiod/data/" then if expr match "$user_fname" "^topdat/$billperiod/data/wbttop.csv" then echo "handle wbttop.csv" # header #User List,November 2012,SDATE,EDATE,UserID_DESC,UserID,DistID_DESC,DistID,BDMethod,BDType,RealeaseDate,RegenDate,LastSentDate #grep 3025 topdat/Nov_2012/data/wbttop.csv #,,,,NEIL ROBERTS,neil.roberts@yarratrams.com.au,Bilmax21 Cost Centre Reports,3025,WEB,INVOICE_PDF,30-11-2012,,30-11-2012 #,,,,NEIL ROBERTS,neil.roberts@yarratrams.com.au,Management Reports,mng3025,WEB,MANAGEMENT,30-11-2012,,30-11-2012 # copy entries for userid, (excluding personal) egrep "^User List,|,${userid}," topdat/$billperiod/data/wbttop.csv |\ grep -v ",PERSONAL," > "zipdat/topdat/$billperiod/data/wbttop.csv" echo "---- zipdat/topdat/data/wbttop.csv ----" cat "zipdat/topdat/$billperiod/data/wbttop.csv" echo "---------------------------" else echo "copy actual data to user in place of symlink for $user_fname" # eg. #topdat/Nov_2012/data/extn1/extn_DEPT2885_CENTRE455_1_13460.csv srcdir=`echo "$user_fname" | cut -c 1-16 ` srcbase=`echo "$user_fname" | cut -c 17- ` ## copy user symlink #usersymlink="topdat/$distiddir/$srcbase" #echo "usersymlink=[$usersymlink]" #ls -altr "$usersymlink" #echo "$usersymlink" | cpio -pvdum zipdat 2>&1 1>/dev/null ( echo "srcdir=[$srcdir] srcbase=[$srcbase]" cd "$srcdir" targdir="../../zipdat/topdat/$distiddir" echo "targdir=[$targdir]" echo "$srcbase" | cpio -pvdum "$targdir" 2>&1 1>/dev/null ) fi else echo "copy as listed in fnamelist: $user_fname" echo "$user_fname" | cpio -pvdum zipdat 2>&1 1>/dev/null fi done # copy topdat/billperiod/data/networkaverage.csv #,,,,VicTrack Rent and Calls - Calls,1,VNUM_10001385,3,428,79028,77.46,25.82 echo "copy VNUMs from topdat/$billperiod/data/networkaverage.csv" #echo "topdat/$billperiod/data/networkaverage.csv" | cpio -pvdum zipdat 2>&1 1>/dev/null # should only copy relevalnt VNUMs, and header egpat="${vnumlist}^Network Average" echo "egpat=[$egpat]" egrep "$egpat" "topdat/$billperiod/data/networkaverage.csv" > "zipdat/topdat/$billperiod/data/networkaverage.csv" # copy common nav files #find topdat/common/nav -depth -print | grep -v ".js" | cpio -pvdum zipdat 2>&1 1>/dev/null ( cd comdat find common/nav -level 0 -depth -print | cpio -pvdum ../zipdat/topdat 2>&1 1>/dev/null find common/nav/mainhome_files -depth -print | cpio -pvdum ../zipdat/topdat 2>&1 1>/dev/null find common/nav/img -depth -print | cpio -pvdum ../zipdat/topdat 2>&1 1>/dev/null find common/nav/icons -depth -print | cpio -pvdum ../zipdat/topdat 2>&1 1>/dev/null find common/nav/Resources -depth -print | cpio -pvdum ../zipdat/topdat 2>&1 1>/dev/null find common/nav/media -depth -print | cpio -pvdum ../zipdat/topdat 2>&1 1>/dev/null ) # copy doc files find topdat/doc -depth -print | cpio -pvdum zipdat 2>&1 1>/dev/null # copy cinf files find topdat/conf/didyouknow.txt -depth -print | cpio -pvdum zipdat 2>&1 1>/dev/null # copy and rename user index html file cp img/xuser.html "zipdat/topdat/$userhtmlfile" # remove symlink copy disclaimer file rm -f "zipdat/topdat/doc/disclaimer.html" cp img/disclaimer.html "zipdat/topdat/doc/disclaimer.html" cd zipdat zipfile="topdat_${distid}_${monthdir}.zip" rm -f $zipfile if [ -n "$WBZIPPWD" ]; then #zip -r -9 $zipfile topdat 2>&1 1>/dev/null #t21zipcloak -P "$WBZIPPWD" $zipfile zip -P "$WBZIPPWD" -e -r -9 $zipfile topdat 2>&1 1>/dev/null else zip -r -9 $zipfile topdat 2>&1 1>/dev/null fi echo "size of zip" zipKsize=`du -k $zipfile | awk '{print $1}'` echo "zipKsize = $zipKsize" if [ $zipKsize -ge $maxKsize ]; then cd .. echo "TOO BIG!" do_email_zip_too_big return fi echo "Sending ZIP." attfiles="$zipfile" toptxtfile="" extra_emtxt="" if [ "$inp_emtxt_opt" = "prepend" -o "$inp_emtxt_opt" = "replace" ]; then extra_emtxt="$inp_emtxt" fi if [ "$inp_emtxt_opt" != "replace" ]; then extratxtfiles="../topdat/$idfile ../emtxt_email_reports.txt" fi bottomtxtfile="../emtxt_disclaimer.txt" if [ "$userid" != "$distid" ]; then idtext="$userid $distid" else idtext="$distid" fi subject="${subjectprefix}Bilmax21 Reports for $idtext $monthtag" emaillist="$email" email_file cd .. } do_email_zip_too_big() { cd zipdat attfiles="" toptxtfile="" extra_emtxt="" if [ "$inp_emtxt_opt" = "prepend" -o "$inp_emtxt_opt" = "replace" ]; then extra_emtxt="$inp_emtxt" fi if [ "$inp_emtxt_opt" != "replace" ]; then extratxtfiles="../topdat/$idfile ../emtxt_moveto_online.txt" fi bottomtxtfile="../emtxt_disclaimer.txt" if [ "$userid" != "$distid" ]; then idtext="$userid $distid" else idtext="$distid" fi subject="${subjectprefix}Bilmax21 Reports for $idtext $monthtag" emaillist="$email" email_file cd .. } #---------------------- do_email_web() { cd zipdat attfiles="" #attfbase=`basename $idfile .txt` #echo "attfbase=[$attfbase]" #attf1="/tmp/${attfbase}.rtf" #echo "attf1=[$attf1]" #cp "../topdat/$idfile" "$attf1" #attfiles="$attf1" toptxtfile="../emtxt_online_top.txt" extra_emtxt="" if [ "$inp_emtxt_opt" = "prepend" -o "$inp_emtxt_opt" = "replace" ]; then extra_emtxt="$inp_emtxt" fi if [ "$inp_emtxt_opt" != "replace" ]; then ##extratxtfiles="../topdat/$idfile ../emtxt_always_online.txt" #extratxtfiles="../emtxt_always_online.txt" extratxtfiles="../emtxt_always_online.txt ../topdat/$idfile" fi bottomtxtfile="../emtxt_disclaimer.txt" if [ "$userid" != "$distid" ]; then idtext="$userid $distid" else idtext="$distid" fi subject="${subjectprefix}Bilmax21 Reports for $idtext $monthtag" emaillist="$email" email_file #rm -f "$attf1" cd .. } #---------------------------------------- do_set_lastsentdate() { today="$1" awk -v"distidlistfile=$distidlistfile" \ -v"onlythisdistid=$onlythisdistid" \ -v"alwayssend=$ALWAYS_SEND" \ -v"curddmmyyyy=$today" \ -v"monthdir=$billperiod" ' function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) return s } function clip(s) { sub(/[ \t]*$/,"",s) return s } function ld_distidlist(fname) { #printf("ld_distidlist(%s)\n", fname) while ( (getline aline < fname) > 0 ) { #print "aline=[" aline "]" split(aline, a_arr, ",") f = 0 reldistid = trim(a_arr[++f]) reldistid_arr[reldistid] = 1 #print "reldistid_arr[" reldistid "] = 1" } close(fname) } BEGIN { if ( distidlistfile != "" ) ld_distidlist(distidlistfile) if ( onlythisdistid != "" ) reldistid_arr[onlythisdistid] = 1 wbttop_fname = sprintf("topdat/%s/data/wbttop.csv", monthdir); print "check wbttop_fname=[" wbttop_fname "]" save_wbttop_fname = sprintf("topdat/%s/data/orig_wbttop.csv", monthdir) # if not already saved, save original wbttop csv file if ( (getline x < save_wbttop_fname) < 0 ) { system("cp " wbttop_fname " " save_wbttop_fname) } close(save_wbttop_fname) tmp_wbttop_fname = sprintf("/tmp/tmp_rse_%s_wbttop.csv", monthdir) countsent = 0 while ( (getline wbttopline < wbttop_fname) > 0 ) { split(wbttopline, wbttop_arr, ",") #print "wbttopline = " wbttopline f = 0 filedesc = clip(wbttop_arr[++f]); exbilperiod = clip(wbttop_arr[++f]); sdate = clip(wbttop_arr[++f]); edate = clip(wbttop_arr[++f]); useriddesc = clip(wbttop_arr[++f]); t21userid = clip(wbttop_arr[++f]); DISTIDdesc = clip(wbttop_arr[++f]); DISTID = clip(wbttop_arr[++f]); t21wbd_method = clip(wbttop_arr[++f]); t21wbd_type = clip(wbttop_arr[++f]); bm_releasedate = clip(wbttop_arr[++f]); bm_regendate = clip(wbttop_arr[++f]); bm_lastsentdate = clip(wbttop_arr[++f]); if ( filedesc != "User List" ) { # not header if ( reldistid_arr[DISTID] == 1 ) { # update lastsent date print "SET lastsentdate in monthdir=" monthdir " for DISTID=[" DISTID "]" " to " curddmmyyyy if (bm_lastsentdate == "" || alwayssend == "Y") bm_lastsentdate = curddmmyyyy wbttopline = sprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", filedesc, exbilperiod, sdate, edate, useriddesc, t21userid, DISTIDdesc, DISTID, t21wbd_method, t21wbd_type, bm_releasedate, bm_regendate, bm_lastsentdate) ++countsent } } printf("%s\n", wbttopline) >>tmp_wbttop_fname } close(wbttop_fname) close(tmp_wbttop_fname) if ( countsent > 0 ) { # replace wbttop with released one system("rtrun cp " tmp_wbttop_fname " " wbttop_fname) #print "-------- NEW " tmp_wbttop_fname "--------" #system("cat " tmp_wbttop_fname) #print "-----------------------------------------------" } system("rm " tmp_wbttop_fname) exit 0 }' } ########################## tmpwfile="t21WBDL_top_$$.csv" workfile="/tmp/${tmpwfile}" # make sure we are here cd $workdir tmpfile="/tmp/emailex4distid$$" rm -f $tmpfile ## Testing exec >$tmpfile 2>&1 echo "$0: SDATE=[$SDATE] EDATE=[$EDATE]" MMYYYY=`SDATEtoMMYYYY $SDATE` echo "MMYYYY = [$MMYYYY]" billperiod=`MMYYYYtobillperiod $MMYYYY _` echo "$MMYYYY - billperiod = [$billperiod]" echo "--------------------------------------------------------------------" date echo "override_email=[$override_email]" echo "ALWAYS_SEND=[$ALWAYS_SEND]" if [ "$onlythisdistid" != "" ]; then echo "Only for distid -- $onlythisdistid" else if [ "$distidlistfile" != "" ]; then echo "For distid's listed in file -- $distidlistfile" else echo "All Configured distid as at last wb4a run" fi fi echo "emailsbeforepause = $emailsbeforepause" echo " pauseinminutes = $pauseinminutes" echo ## make sure we are here #cd ${workdir}/topdat # remove zip files and dir #rm -rf zipdat #mkdir zipdat ########################## # create working file rm -f "$workfile" echo "Creating T21 WBDL work file: $workfile" ## ##gett21WBDL "$SDATE" "$EDATE" STIME ETIME "$SITEID" "$tmpwfile" ##cp "$tmpwfile" "$workfile" ##rm -f "$tmpwfile" ## #t21WBDLfile="t21WBDL.unl" #t21WBDLdir="indata/${billperiod}" #echo "Copying ${t21WBDLdir}/${t21WBDLfile} to $workfile" #cp "${t21WBDLdir}/${t21WBDLfile}" "$workfile" t21WBDLfile="wbttop.csv" t21WBDLdir="topdat/${billperiod}/data" echo "Copying ${t21WBDLdir}/${t21WBDLfile} to $workfile" cp "${t21WBDLdir}/${t21WBDLfile}" "$workfile" #################### #last_distid="" emailssent="0" # wbttop #User List,September 2006,SDATE,EDATE,UserID_DESC,UserID,DistID_DESC,DistID,BDMethod,BDType #,,,,TOM MILLAR,9030048,Personal Reports for TOM MILLAR,9030048,WEB,PERSONAL cat $workfile | \ while read waline do echo "waline=[$waline]" eval `echo "$waline" | awk -F',' '{ printf(" fld1=\"%s\"; useriddesc=\"%s\"; userid=\"%s\"; distiddesc=\"%s\"; distid=\"%s\"; wbd_method=\"%s\"; wbd_type=\"%s\"; ", $1, $5, $6, $7, $8, $9, $10) }' ` if [ -n "$fld1" ]; then if [ "$fld1" = "User List" ]; then # skip header #echo "SKIP Header=[$waline]" continue fi fi ## if done already (ie.skip multiple grids) #if [ "$last_distid" = "$distid" ]; then # last_distid="$distid" # continue #fi if [ -n "$onlythisdistid" -a "$onlythisdistid" != "$distid" ]; then echo "SKIP distid = $distid" echo "" #last_distid="$distid" continue fi indistidlist="0" if [ -n "$distidlistfile" ]; then if grep "^${distid}$" "$distidlistfile" > /dev/null then # in list file #echo "Do in list file distid = $distid" indistidlist="1" else # not in list file #echo "SKIP (not in list file) distid = $distid" continue fi fi # force upper case wbd_type=`echo "$wbd_type" | awk '{print toupper($1)}'` recordno="" lastdist="" lastdistdate="" altemail="" altemailyn="N" if [ $wbd_type = "PERSONAL" ];then if [ "$DO_PERSONAL" = "N" ]; then echo "SKIP distid = $distid wbd_type = $wbd_type" continue fi echo "DO distid = $distid wbd_type = $wbd_type" else # assume STANDARD echo "DO distid = $distid wbd_type = $wbd_type" # get email address from current wbdconf DB table sqlmy_status "Finding altemail for distid=$distid" procsql ":" "select unique wbdconf.recordno, wbdconf.lastdist, wbdconf.lastdistdate, wbdconf.altemail, wbdconf.altemailyn from wbdconf where distid = \"$distid\"" echo "nrows=$nrows" echo "recordno = [$recordno]" echo "altemail = [$altemail]" echo "altemailyn = [$altemailyn]" # force upper case altemailyn=`echo "$altemailyn" | awk '{print toupper($1)}'` if [ "$altemailyn" = "" -o "$altemail" = "" ]; then altemailyn="N" fi fi ## try to get email addres from current directcustom DB table ##echo "recordno = [$recordno]" #if [ "$recordno" != "" ]; then # # use recordno from wbdconf (STANDARD) # where_bit="where directcustom.recordno = $recordno" #else # # use userid from wbttop csv to lookup StaffID (PERSONAL) # where_bit="where directcustom.$WB_USERNAME_DIRCUST_FIELD = \"$userid\"" #fi #if [ "$wbd_type" = "PERSONAL" ]; then # where_bit="$where_bit and directcustom.recordno in (select directoryid from sidconf)" #fi ##sqlmy_status "Finding directcustom_email for distid=$distid" ##sqlmy_status " where_bit=$where_bit" #directcustom_email="" #procsql ":" "select unique directcustom.recordno, directcustom.email directcustom_email from directcustom $where_bit" ##echo "nrows=$nrows" ##echo "recordno = [$recordno]" ##echo "directcustom_email = [$directcustom_email]" ##email="$directcustom_email" # get email from cached tPerson sqlmy_status "Finding tperson.emailaddress for distid=$distid" procsql ":" "select unique tperson.personid, tperson.emailaddress tperson_email from tperson where tperson.personid = $recordno" echo "nrows=$nrows" echo "personid = [$recordno]" echo "tperson_email = [$tperson_email]" email="$tperson_email" if [ "$altemailyn" = "Y" -a "$altemail" != "" ]; then email="$altemail" fi # force upper case wbd_method=`echo "$wbd_method" | awk '{print toupper($1)}'` # Testing wbd_method="OFFLINE" if [ "$wbd_method" = "OFFLINE" ]; then offlineyn="Y" else offlineyn="N" fi if [ "$wbd_method" = "EMAIL" ]; then emailyn="Y" else emailyn="N" fi if [ "$wbd_method" = "WEB" ]; then webyn="Y" else webyn="N" fi if [ -z "$userid" ]; then # if [ -z "$recordno" ]; then # echo "ERROR: NO userid or recordno for distid=$distid" # last_distid="$distid" # continue # fi # echo "WARNING: NO userid - using recorno=$recordno for distid=$distid" # userid="$recordno" #else # userid="$userid" echo "ERROR: NO userid for distid=$distid" echo "" continue fi monthdir="$billperiod" if [ ! -d "topdat/$monthdir" ]; then echo "ERROR: NO data for monthdir = $monthdir" #last_distid="$distid" continue fi distiddir="$billperiod/$distid" if [ ! -d "topdat/$distiddir" ]; then echo "ERROR: NO data for distiddir = $distiddir" #last_distid="$distid" continue fi subjectprefix="" # if not set to email OR web OR offline if [ "$emailyn" != "Y" -a "$webyn" != "Y" -a "$offlineyn" != "Y" ]; then echo "ERROR: Distribution List distid = $distid is NOT SET for EMAIL OR WEB OR OFFLINE" #last_distid="$distid" continue fi if [ -z "$email" ]; then echo "ERROR: NO email address for $distid" #last_distid="$distid" #continue email="$WBADMINEMAIL" subjectprefix="No Email Address for - " fi echo "" echo "DO..." echo " recordno = $recordno" echo " distid = $distid" echo " distiddesc = $distiddesc" echo " lastdist = $lastdist" echo "lastdistdate = $lastdistdate" echo " altemail = $altemail" echo " altemailyn = $altemailyn" echo " wbd_method = $wbd_method" echo " wbd_type = $wbd_type" echo " userid = $userid" #echo " directcustom_email = $directcustom_email" echo "monthdir=$monthdir" echo "distiddir=$distiddir" echo "offlineyn=$offlineyn" echo "emailyn=$emailyn" echo "webyn=$webyn" ## get username #t21name=`grep "^$recordno," "indata/${billperiod}/T21E.csv" | awk -F',' '{ t21name = $3; if (t21name != "") t21name = t21name " "; t21name = t21name $2; print t21name; }'` # may not be in Telmax21 Directory (use distiddesc) t21name="$distiddesc" echo "t21name=[$t21name]" # get ShipTo for distid echo "get ShipTo for distid=$distid userid=[$userid]" distidcsv="topdat/${billperiod}/$distid/data/distid/distid_${distid}.csv" echo "distidcsv=[$distidcsv]" echo "---- VNUMs ----" #awk -F',' '{ if (NR > 1) print $7 }' < "$distidcsv" | sort -u vnumlist=`awk -F',' ' { if ( NR > 1 && have_vnum[$7] == "" ) { vnums = vnums $7 "|" have_vnum[$7] = "1" } } END { print vnums } ' < "$distidcsv"` echo "vnumlist=[$vnumlist]" echo "" echo "---- ShipToDescs ----" #awk -F',' '{ if (NR > 1) print $8 }' < "$distidcsv" | sort -u shiptodesclist=`awk -F',' ' { if ( NR > 1 && have_shiptodesc[$8] == "" ) { shiptodescs = shiptodescs $8 "|" have_shiptodesc[$8] = "1" } } END { print shiptodescs } ' < "$distidcsv"` echo "shiptodesclist=[$shiptodesclist]" echo "" echo "---- ShipTos ----" #awk -F',' '{ if (NR > 1) print $9 }' < "$distidcsv" | sort -u shiptolist=`awk -F',' ' { if ( NR > 1 && have_shipto[$9] == "" ) { shiptos = shiptos $9 "|" have_shipto[$9] = "1" } } END { print shiptos } ' < "$distidcsv"` echo "shiptolist=[$shiptolist]" echo "" # idfile="${distiddir}/${distid}_${billperiod}.txt" fnamelistfile="${distiddir}/fnamelist.csv" userhtmlfile="${userid} ($distid - $t21name) Click here to run your reports.html" monthtag=`echo "$billperiod" | tr ' ' '-'` idtag="$distid $monthtag" echo "idfile=$idfile idtag=$idtag monthtag=$monthtag" echo "fnamelistfile=$fnamelistfile" echo "userhtmlfile=$userhtmlfile" if [ "$lastdist" = "$monthtag" ]; then if [ "$ALWAYS_SEND" != "Y" ]; then echo "WARNING: $distid Already sent" #last_distid="$distid" continue fi fi ## Testing if [ "$offlineyn" = "Y" ]; then do_build_offline fi ## Testing if [ "$emailyn" = "Y" ]; then do_email_zip fi ## Testing if [ "$webyn" = "Y" ]; then do_email_web fi ######################################## # remove workdir rm -f -r zipdat/topdat ############### ## Testing #echo "Testing - should update lastdist for $distid" #last_distid="$distid" #echo "" #continue #if [ "$ALWAYS_SEND" = "Y" ]; then # #last_distid="$distid" # echo "Resend - SKIP update lastdist" # echo "" #else echo "Before update lastdist wbd_type=[$wbd_type]" # update lastdist case $wbd_type in [STANDARD|INVOICE_PDF|ADMIN|BILMAX21|WBDM_DIST_ADMIN|WBDM|DISTID_ADMIN|WBDM_LIST_ADMIN|WBDM_USER_ADMIN]) # Testing echo "WOULD: update wbdconf \ set lastdist = \"$monthtag\", \ lastdistdate = \"$today\" \ where distid = \"$distid\"" #result=`echo "update wbdconf \ # set lastdist = \"$monthtag\", \ # lastdistdate = \"$today\" \ # where distid = \"$distid\"" | \ # runisql 2>&1 | grep -c "1 row(s) updated"` #echo "update lastdist for $distid result = [$result]" #if [ $result -ne 1 ]; then # echo "ERROR update lastdist: distid $distid" # #exit 1 # continue #fi ;; esac #fi ######################################## emailssent=`expr $emailssent + 1` echo "emailssent = $emailssent emailsbeforepause = $emailsbeforepause" # Testing #if [ $emailsbeforepause -gt 0 ]; then # moda=`expr $emailssent % $emailsbeforepause` # if [ $moda -eq 0 ]; then # if [ $pauseinminutes -gt 0 ]; then # pauseinseconds=`expr $pauseinminutes \* 60` # echo "PAUSING... pauseinminutes = $pauseinminutes pauseinseconds = $pauseinseconds" # #echo "should: sleep $pauseinseconds" # sleep $pauseinseconds # fi # fi #fi #last_distid="$distid" echo " -- loop ---" done echo "here done" ########################################### # update lastsentdate in wbttopcsv # Testing #do_set_lastsentdate "$today" ########################################### echo "" echo "" echo "" echo "" ####################################################### # save log ## Testing cat $tmpfile >>${workdir}/emex4_${billperiod}.log #output file to user # Testing #cat $tmpfile | pr_rep system emex4_ rm -f $workfile rm -f $tmpfile exit 0