: !/bin/sh # wb4retro umask 002 #SITEID="101" SITEID="ALL" export SITEID #----------------------------------------- # setup for creation of retro distid lists retroBDL="1" export retroBDL . /u/catcom/catcom_vars if [ -z "$WB_RUNDAY" ]; then WB_RUNDAY="1" fi export WB_RUNDAY #----------------------------------------- # check Bimax21 is not already running # this will exit if wb4 is running . gwb4proc #----------------------------------------- lastdayinmonth() # Returns the last day in month, Inputs: $1=mm $2=yyyy { cal $1 $2 | awk '{ if ( NF > 0 ) x=$NF } END { print x }' } dec_mm_yyyy() { mm=`expr $mm - 1 | awk '{printf("%02d\n",$1)}'` if [ $mm -lt 1 ]; then mm=12 yyyy=`expr $yyyy - 1 | awk '{printf("%04d\n",$1)}'` fi edd=`lastdayinmonth $mm $yyyy` echo "dec_mm_yyy $sdd-$edd $mm/$yyyy" } inc_mm_yyyy() { # increment month mm=`expr $mm + 1 | awk '{printf("%02d\n",$1)}'` if [ $mm -gt 12 ]; then mm=01 yyyy=`expr $yyyy + 1 | awk '{printf("%04d\n",$1)}'` fi edd=`lastdayinmonth $mm $yyyy` echo "inc_mm_yyy $sdd-$edd $mm/$yyyy" } #----------------------------------------- # loop from oldest to newest month allowed to be regenerated # this month curyyyy=`date "+%Y"` curmm=`date "+%m"` curdd=`date "+%d"` syyyy=$curyyyy smm=$curmm sdd=01 edd=`lastdayinmonth $mm $yyyy` yyyy=$syyyy mm=$smm # last month dec_mm_yyyy; # if before billmax21 first phase run # move back a month before last month if [ $curdd -lt $WB_RUNDAY ]; then dec_mm_yyyy fi eyyyy=$yyyy emm=$mm sdd=01 edd=`lastdayinmonth $mm $yyyy` # get oldest mont allowed to be regenerated i=1 while true do if [ $i -gt 12 ]; then break fi i=`expr $i + 1` dec_mm_yyyy done # loop for each month while true do SDATE="$sdd/$mm/$yyyy" EDATE="$edd/$mm/$yyyy" echo "" echo "" echo "Do SDATE=[$SDATE] ... EDATE=[$EDATE]" ################################ MMYYYY=`SDATEtoMMYYYY $SDATE` echo "MMYYYY = [$MMYYYY]" billperiod=`MMYYYYtobillperiod $MMYYYY _` echo "$MMYYYY - billperiod = [$billperiod]" ###################################################################### # Phase 1... generate new WBDM list of distids to generat for the month t21WBDLfile="t21WBDLr.unl" if wb4ra "$SDATE" "$EDATE" STIME ETIME $SITEID all then hasretro="1" else hasretro="0" fi if [ -f "$t21WBDLfile" ]; then echo "---- $hasretro -----" cat "$t21WBDLfile" echo "--------------------" else echo "---- ERROR hasretro = $hasretro - NO file: $t21WBDLfile -----" hasretro="0" export hasretro fi if [ "$hasretro" = "1" ]; then ############################################################### # Phase 2... generate web billing images / reports / csv T21BATCHVAR1VALU="$retroBDL" export T21BATCHVAR1VALU ## only this distid #T21BATCHVAR2VALU="1099" #export T21BATCHVAR2VALU thisCENTRE="all" #thisCENTRE="20211" if [ "$retroBDL" != "1" ]; then logf="wb4_${thisCENTRE}.out" else logf="wb4r_${thisCENTRE}.out" fi echo "wb4retro: Running: wb4 "$SDATE" "$EDATE" STIME ETIME $SITEID $thisCENTRE 1" (time wb4 "$SDATE" "$EDATE" STIME ETIME $SITEID $thisCENTRE 1 2>&1) >"$logf" ############################################################### # update wbdcreate for each distid generated in month #209079|1076|Trans-Mit Bilmax21 Test List|Oct_2006|10/11/2006|||WEB|STANDARD|transmit|126w./Ixr5h12|01/01/2004||CP001214|support@transmit.com.au|Feb_2007|||| #209079|1076|Trans-Mit Bilmax21 Test List|Oct_2006|10/11/2006|||WEB|STANDARD|transmit|126w./Ixr5h12|01/01/2004||23621|support@transmit.com.au|Feb_2007|||| cat "$t21WBDLfile" | \ while read aline do #echo "aline=[$aline]" eval `echo "$aline" | awk -F'|' '{ printf("distiddesc=\"%s\"; distid=\"%s\"; ", $3, $2) }' ` # if done already (ie.skip multiple grids) if [ "$last_distid" = "$distid" ]; then continue fi echo "distiddesc=[$distiddesc] distid=[$distid]" echo "update wbdcreate set created = \"$billperiod\", createddate = TODAY where distid = $distid" | runisql 2>&1 # clear lastsent date echo "update wbdconf set lastdist = NULL, lastdistdate = NULL where distid = $distid" and lastdist = \"$billperiod\" | runisql 2>&1 last_distid="$distid" done ################################################## # copy entire month to the DMZ Bilmax21 cpWBDL2dmz $billperiod cpdat2dmz $billperiod fi ############################################################ # move forward a month and break out if we are past end date inc_mm_yyyy echo "bottom of loop yyyymm=[$yyyy$mm] eyyyyemm=[$eyyyy$emm]" if [ $yyyy$mm -gt $eyyyy$emm ]; then break fi done ####################################################### # set completed in wbdcreate for each distid generated cat "$t21WBDLfile" | \ while read aline do #echo "aline=[$aline]" eval `echo "$aline" | awk -F'|' '{ printf("distiddesc=\"%s\"; distid=\"%s\"; ", $3, $2) }' ` # if done already (ie.skip multiple grids) if [ "$last_distid" = "$distid" ]; then continue fi echo "distiddesc=[$distiddesc] distid=[$distid]" #################### # set completed data echo "update wbdcreate set completeddate = TODAY where distid = $distid" | runisql 2>&1 last_distid="$distid" done exit 0