: !/sh ######################################################################## # T21BATCHNAME extgroup1.t21batch # T21BATCHDESC Extension Group Batch Report # ALLOWBLANKDATES false # CUSTOMDESC Email Address # CUSTOMDEF `cat /u/catcom/database/reports.emaillist` # T21BATCHVAR1DESC Enter Extension GroupID (space delimited list) # T21BATCHVAR1VALU ALL # T21BATCHVAR2DESC # T21BATCHVAR2VALU # T21BATCHVAR3DESC # T21BATCHVAR3VALU # T21BATCHVAR4DESC # T21BATCHVAR4VALU # T21BATCHVAR5DESC Enter Extension (space delimited list) # T21BATCHVAR5VALU 87907 87910 87912 87913 87914 87917 87933 # T21BATCHENDARGS ######################################################################## # command line args SDATE=$1; EDATE=$2; STIME=$3; ETIME=$4 if [ -n "$5" ]; then SITEID="$5" else SITEID="ALL" fi if [ -n "$6" ]; then CUSTPARAM="$6" else CUSTPARAM="$LOGNAME" fi EMAIL_ADDRESS="$CUSTPARAM" if [ -n "$T21BATCHVAR1VALU" ]; then EGRIDLIST="$T21BATCHVAR1VALU" else EGRIDLIST="" fi if [ -n "$T21BATCHVAR5VALU" ]; then EXTNLIST="$T21BATCHVAR5VALU" else EXTNLIST="ALL" fi GENGROUP="Nulls" ################################################################# lastdayinmonth() # Returns the last day in month, Inputs: $1=mm $2=yyyy { cal $1 $2 | awk '{ if ( NF > 0 ) x=$NF } END { print x }' } monthname() # Returns the month name, Inputs: $1=mm { awk -v "mm=$1" 'BEGIN { monthnamearr[1] = "Jan" monthnamearr[2] = "Feb" monthnamearr[3] = "Mar" monthnamearr[4] = "Apr" monthnamearr[5] = "May" monthnamearr[6] = "Jun" monthnamearr[7] = "Jul" monthnamearr[8] = "Aug" monthnamearr[9] = "Sep" monthnamearr[10] = "Oct" monthnamearr[11] = "Nov" monthnamearr[12] = "Dec" print monthnamearr[mm + 0] exit 0 }' } ################################################################# # MAIN umask 0 ################################################################# if [ -z "$SITEID" ]; then echo "Enter siteid (Enter for ALL):\c"; read SITEID fi if [ -z "$SITEID" ]; then SITEID="ALL" fi if [ "$SITEID" = "ALL" ]; then SITEID="Nulls" 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:\c"; read STIME fi if [ -z "$ETIME" ]; then echo "Enter end time:\c"; read ETIME fi if [ -z "$EGRIDLIST" ]; then echo "Enter ExtnGroupIDList (Enter for ALL):\c"; read EGRIDLIST fi if [ -z "$EGRIDLIST" ]; then EGRIDLIST="ALL" fi if [ "$EGRIDLIST" = "ALL" ]; then EGRIDLIST="Nulls" fi if [ -z "$EXTNLIST" ]; then echo "Enter Extn (space delim list) (Enter for ALL):\c"; read EXTN fi if [ -z "$EXTNLIST" ]; then EXTNLIST="ALL" fi ########################################################################### # temp files tmpfile="/tmp/extgroup1__$$" tmp1file="/tmp/extgroup1_1_$$" tmp2file="/tmp/extgroup1_2_$$" ########################################################################### ########################################################################### ########################################################################### ########################################################################### # send script output output to file exec >$tmpfile 2>&1 ########################################################################### echo "Starting extgroup1.t21batch: $SDATE $EDATE $SITEID \"$GENGROUP\" \"$EGRIDLIST\" $EMAIL_ADDRESS" date sdd=`echo $SDATE | sed -e 's/\/..\/....$//g'` smm=`echo $SDATE | sed -e 's/^..\///g;s/\/....$//g'` syyyy=`echo $SDATE | sed -e 's/^..\/..\///g'` edd=`echo $EDATE | sed -e 's/\/..\/....$//g'` emm=`echo $EDATE | sed -e 's/^..\///g;s/\/....$//g'` eyyyy=`echo $EDATE | sed -e 's/^..\/..\///g'` # set month and year to be used in filename MMM_YYYY="`monthname ${smm}`_${syyyy}" ######################################################################### ######################################################################### ########################################################################### # prepare for report output setting to be controlled within this script # disable rpt options set if spooled if [ "$spoolt21rptopts" = "1" ]; then spoolt21rptopts=0 export spoolt21rptopts runont21_pid=$rptque_pid fi # make sure runont21_pid is set for srct21rptopts script to find temp rpt opts if [ -z "$runont21_pid" ]; then runont21_pid="$$" fi export runont21_pid # must be set so pr_rep sets uue_pid dobatch_pid=$runont21_pid; export dobatch_pid # set pr_rep env file name for concat/email ALL-IN-ONE if [ -z "$pr_rep_env_file" ]; then pr_rep_env_file="$HOME/pr_rep.env$runont21_pid" export pr_rep_env_file fi ####################################################################### ####################################################################### # setup report output options to be # csv # concatenateed output to tmp1file (using tee filter) RPTOPTSTEMP="tmp/.t21rptopts.tmp$runont21_pid" cat > $HOME/$RPTOPTSTEMP < $HOME/$RPTOPTSTEMP < 0 ) durstr = sprintf("%4d:%02d:%02d", durhh, durmm, durss) #else # durstr = sprintf(" %02d:%02d", durmm, durss) return durstr } { # spit header rec if ( NR == 1 ) { print $0 NTOT = NF next } #date from, #date to, #site, #group, #group description 1, #group description 2, #parent group, #parent group description, #type, #description, #extension/account code, #oint_cnt, #aint_cnt, #free_cnt, #inet_cnt, #onet_cnt, #ipub_cnt, #loc_cnt, #std_cnt, #idd_cnt, #mob_cnt, #inf_cnt, #tot_cnt, #oint_durs, #oint_dur, #aint_durs, #aint_dur, #free_durs, #free_dur, #inet_durs, #inet_dur, #onet_durs, #onet_dur, #ipub_durs, #ipub_dur, #loc_durs, #loc_dur, #std_durs, #std_dur, #idd_durs, #idd_dur, #mob_durs, #mob_dur, #inf_durs, #inf_dur, #tot_durs, #tot_dur, #onet_cst, #loc_cst, #std_cst, #idd_cst, #mob_cst, #inf_cst, #tot_cst, #equip_charge, #oh_cst, #misc_cst, #GST extn = $11 #print "0 (extn=" extn "): " $0 #print "test include_extn[" extn "]=[" include_extn[extn] "]" if ( include_extn[extn] == 1 ) { print $0 #do totals for ( i = 1; i <= NF; ++i ) { if ( i >= 12 ) tot_fld[i] += (0 + $i) else tot_fld[i] = "" #if ( i == 15 ) # print "tot_fld[" i "]=[" tot_fld[i] "]" } } } END { # output totals outp = "" for ( i =1; i <= NTOT; ++i ) { if ( i > 1 ) outp = outp "," fldstr = tot_fld[i] # create hh:mm::ss total value form prev dur (seci) fields if ( i == 25 || i == 27 || i == 29 || i == 31 || i == 33 || i == 35 || i == 37 || i == 39 || i == 41 || i == 43 || i == 45 || i == 47 ) fldstr = to_hhmmss(0 + outp tot_fld[i-1]) outp = outp fldstr } print outp } ' > "$tmp2file" # send output to user cat "$tmp2file" | pr_rep system extgroup1_ ########################################################################### echo "Finished $0 " date ############################################################ ############################################################ ############################################################ ############################################################ # handle concat/email ALL-IN-ONE option # must do it here because rptque will have spoolt21rptopts set # and therefore srct21rptopts will not get RPTOPTSTEMP from above t21em_subject="Extension Group Batch Reports" export t21em_subject t21em_content="\ Please find the attached Extension Group Batch Reports\nFiltered for Extensions $EXTNLIST\n" export t21em_content t21em_content_file="$tmpfile" export t21em_content_file if [ "$pr_rep_env_file" = "" ]; then echo "$0: pr_rep_env_file env var NOT SET" fi if [ -f "$pr_rep_env_file" ]; then # handle concat and email all in one options if [ "$t21fileconcat" = "Y" -o \ \( "$t21emailyn" = "Y" -a "$t21emailuuencode" = "3" \) ] then handlet21rpt fi fi # remove temp rptopts file rm -f $HOME/$RPTOPTSTEMP ########################################################################### #cp $tmpfile 0 #cp $tmp1file 1.csv #cp $tmp2file 2.csv ########################## rm -f $tmpfile rm -f $tmp1file rm -f $tmp2file exit 0 # end