: !/bin/sh ######################################################################## # T21BATCHNAME peak15.t21batch # T21BATCHDESC Peak average 15 min Report # ALLOWBLANKDATES false # CUSTOMDESC Email Address # CUSTOMDEF `cat /u/catcom/database/reports.emaillist` # T21BATCHVAR1DESC Enter Route Type # T21BATCHVAR1VALU K # T21BATCHVAR2DESC Occupancy Based On Configured or Used # T21BATCHVAR2VALU C # T21BATCHVAR3DESC Dialled Prefix # T21BATCHVAR3VALU ALL # T21BATCHVAR4DESC Include Weekends # T21BATCHVAR4VALU N # T21BATCHVAR5DESC Enter RouteID # T21BATCHVAR5VALU ALL # 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 if [ -n "$T21BATCHVAR1VALU" ]; then ROUTETYPE="$T21BATCHVAR1VALU" else ROUTETYPE="T" fi if [ -n "$T21BATCHVAR2VALU" ]; then OCCBASE="$T21BATCHVAR2VALU" else OCCBASE="C" fi if [ -n "$T21BATCHVAR3VALU" ]; then DIALLEDPREFIX="$T21BATCHVAR3VALU" else DIALLEDPREFIX="" fi if [ -n "$T21BATCHVAR4VALU" ]; then INCLUDEWEEKENDS="$T21BATCHVAR4VALU" else INCLUDEWEEKENDS="Y" fi if [ -n "$T21BATCHVAR5VALU" ]; then ROUTEID="$T21BATCHVAR5VALU" else ROUTEID="ALL" fi ################################################################# 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 [ -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 "$ROUTEID" ]; then echo "Enter Route ID(Enter for ALL):\c"; read ROUTEID fi if [ -z "$ROUTEID" ]; then ROUTEID="ALL" fi if [ -z "$ROUTETYPE" ]; then echo "Enter Route Type(Enter for ALL):\c"; read ROUTETYPE fi if [ -z "$ROUTETYPE" ]; then ROUTETYPE="ALL" fi if [ -z "$OCCBASE" ]; then echo "Enter Occupancy based On Configured or Used or Actual (c/u/a):\c"; read OCCBASE fi if [ "$OCCBASE" = "U" -o "$OCCBASE" = "u" ]; then OCCBASE="U" else if [ "$OCCBASE" = "A" -o "$OCCBASE" = "a" ]; then OCCBASE="A" else OCCBASE="C" fi fi if [ -z "$DIALLEDPREFIX" ]; then echo "Enter Dialled Prefix (Enter for ALL):\c"; read DIALLEDPREFIX fi if [ -z "$DIALLEDPREFIX" ]; then DIALLEDPREFIX="ALL" fi if [ -z "$INCLUDEWEEKENDS" ]; then echo "Enter Include Weekends (y/n):\c"; read INCLUDEWEEKENDS fi if [ "$INCLUDEWEEKENDS" = "N" -o "$INCLUDEWEEKENDS" = "n" ]; then INCLUDEWEEKENDS="N" else INCLUDEWEEKENDS="Y" fi if [ -z "$CUSTPARAM" ]; then echo "Enter Email Address:\c"; read CUSTPARAM fi if [ -n "$CUSTPARAM" ]; then EMAIL_ADDRESS="$CUSTPARAM" else EMAIL_ADDRESS="$LOGNAME" fi ######################################################################### # setup for SQL if [ "$SITEID" = "ALL" ]; then SITEBIT="" else SITEBIT="and siteid = $SITEID" fi ######################################################################### # fix params for running report if [ "$SITEID" = "ALL" ]; then SITEID="Nulls" fi if [ "$ROUTEID" = "ALL" ]; then ROUTEID="Nulls" fi if [ "$ROUTETYPE" = "ALL" ]; then ROUTETYPE="Nulls" fi if [ "$DIALLEDPREFIX" = "ALL" ]; then DIALLEDPREFIX="Nulls" fi ########################################################################### # temp files tmpfile="/tmp/peak15_$$" tmp1file="/tmp/peak15_1_$$" tmp2file="/tmp/peak15_2_$$" ########################################################################### ########################################################################### ########################################################################### ########################################################################### # send script output output to file exec >$tmpfile 2>&1 ########################################################################### echo "Log..." echo "" echo "Starting $0: $SDATE $EDATE $STIME $ETIME $SITEID $ROUTEID $ROUTETYPE $OCCBASE $DIALLEDPREFIX $INCUDEWEEKENDS" date ######################################################################### ######################################################################### ########################################################################### # 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 temp report output options to be # standard unix csv to stdout RPTOPTSTEMP="tmp/.t21rptopts.tmp$runont21_pid" cat > $HOME/$RPTOPTSTEMP < "$tmp1file" ############################################################ # process rtoc CSV into final CSV ( awk -v"MMM_YYYY=${MMM_YYYY}" -v "logfile=$tmpfile" ' function trim(s) { sub(/^[ \t]*/,"",s) sub(/[ \t]*$/,"",s) return s } function clip(s) { sub(/[ \t]*$/,"",s) return s } 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) } BEGIN { } { #print $0 #print "1=[" $1 "]" "2=[" $2 "]" "3=[" $3 "]" "4=[" $4 "]" "5=[" $5 "]" "6=[" $6 "]" "7=[" $7 "]" "8=[" $8 "]" "23,24,25=[" $23 $24 $25 "]" #run: rtdistsum 01/06/2007 30/06/2007 2 Nulls Nulls 00:00 24:00 N C Nulls if ( $1 == "run:" && $2 == "rtdistsum" ) { sdate = $3 edate = $4 inp_siteid = ($5 == "Nulls") ? "All" : $5 routetype = ($6 == "Nulls") ? "All" : $6 inp_routeid = ($7 == "Nulls") ? "All" : $7 stime = $8 etime = $9 includeweekends = $10 occbase = $11 dialledprefix = ($12 == "Nulls") ? "All" : $12 siteid = "" sitedesc = "" routeid = "" routedesc = "" peakinterval_percent_occupancy = 0 } # got from initial run: line # Date From: 02/06/1996 To 02/06/1996 Include Weekends: Y # Site ID: 2 Site Name: Trunk Range: 3001 - 3060 if ( $1 == "Site" && $2 == "ID:" ) { siteid = $3 sitedesc = trim(substr($0, 75, 20)) routeid = "" routedesc = "" totalocc = "" timerangeocc = "" busyminutecalls = "" busyminute = "" busyminutedate = "" busyhour = "" busyhourocc = "" busyhourerlang = "" } # Route ID: 3 Route Name: SSB-SSA Configured Trunks: 60 if ( $1 == "Route" && $2 == "ID:" ) { routeid = $3 routedesc = trim(substr($0, 75, 20)) } # got from initial run: line # Time Range From: 00:00 To 24:00 Used Trunks: 55 #Occupancy Based On: C (Configured Trunks) ######################## # process time intervals # 17:45-18:00 .37 3 6 00:11:12 1.9 . if ( substr($1,3,1) == ":" && substr($1,6,1) == "-" && substr($1,9,1) == ":") { percent_occupancy = trim($6) if ( percent_occupancy >= peakinterval_percent_occupancy ) { timeinterval = trim($1) erlang = trim($2) peak_calls = trim($3) total_calls = trim($4) occupancy = trim($5) peakinterval_percent_occupancy = percent_occupancy } } ############### # end of report #R O U T E H I S T O G R A M R E P O R T PAGE 3 E N D if ( $1 == "R" && $2 == "O" && $3 == "U" && $4 == "T" && $5 == "E" && $23 == "E" && $24 == "N" && $25 == "D" ) { # get routtype sql1 = sprintf("select unique routetype from routetrunk where siteid = %d and routeid = %d", siteid, routeid) sql1 = dosql( sql1 ); routetype = "" while ((getline aline < sql1) > 0) { split(aline, sql1_arr, "|") routetype = sql1_arr[1] break } closesql(sql1) # store outvals_arr[++nvals] = sprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", siteid, sitedesc, routeid, routedesc, routetype, MMM_YYYY, sdate, edate, timeinterval, erlang, peak_calls, total_calls, occupancy, peakinterval_percent_occupancy) #printf("stime=%s etime=%s includeweekends=%s occbase=%s dialldprefix=%s PEAKINTERVAL: %s\n", stime, etime, includeweekends, occbase, dialldprefix, outvals_arr[nvals]) peakinterval_percent_occupancy = 0 } continue } END { # ouput data for ( nval in outvals_arr ) { print outvals_arr[nval] } } ') <"$tmp1file" >"$tmp2file" ########################################################################### ########################################################################### ########################################################################### # setup report output options to be # text with "csv" file extension # emailed as file attchments ALL-In-ONE email RPTOPTSTEMP="tmp/.t21rptopts.tmp$runont21_pid" cat > $HOME/$RPTOPTSTEMP <