: /bin/sh ################################################################# # batch file for creating calls summary data # CUSTOMDESC # CUSTOMDEF progname=$0 SDATE=$1; EDATE=$2; STIME=$3; ETIME=$4 if [ -n "$5" ]; then SITEID=$5 fi if [ -n "$6" ]; then INFILE=$6 else INFILE="c9.in" fi OUTFILE="sum_c9.in" echo "SDATE=$SDATE" echo "EDATE=$EDATE" echo "STIME=$STIME" echo "ETIME=$ETIME" echo "SITEID=$SITEID" echo "INFILE=$INFILE" echo "OUTFILE=$OUTFILE" ################################################################# 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 TMPSTABLE="cdr2$LOGNAME" tmpfile=/tmp/cdr_$$ rm -f $tmpfile 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 [ "$SITEID" = "ALL" ]; then SITEBIT="" else SITEBIT="and siteid = $SITEID" fi ############################################### awk -F ',' -v "sdate=$SDATE" -v "edate=$EDATE" ' BEGIN { t21serviceprovider = "TELMAX21" t21seid = "1021" last_ggrid = "Invalid ggrid" last_egrid = "Invalid egrid" tot_cost = 0.0 } function spit_tot_cost() { printf("%s,%s,%s,%s,%.2f\n", t21serviceprovider, t21seid, ggrid, egrid, tot_cost); tot_cost = 0.0 } { ggrid = $1 egrid = $2 cost = $13 if ( ggrid != last_ggrid || egrid != last_egrid ) { spit_tot_cost() } tot_cost += cost last_ggrid = ggrid last_egrid = egrid } END { spit_tot_cost() } '< "$INFILE" >$tmpfile # send file to user cp $tmpfile $OUTFILE rm -f $tmpfile exit 0