: /bin/sh ################################################################# # batch file for finding calls # CUSTOMDESC # CUSTOMDEF progname=$0 SDATE=$1; EDATE=$2; STIME=$3; ETIME=$4 if [ -n "$5" ]; then SITEID=$5 fi echo "SDATE=$SDATE" echo "EDATE=$EDATE" echo "STIME=$STIME" echo "ETIME=$ETIME" echo "SITEID=$SITEID" if [ -n "$6" ]; then P6=$6 else P6="" 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 }' } ################################################################# # MAIN TMPSTABLE="cdr2$LOGNAME" tmpfile=/tmp/cdr_$$ tmpfile0=/tmp/cdr0_$$ tmpfile1=/tmp/cdr1_$$ tmpfile2=/tmp/cdr2_$$ rm -f $tmpfile rm -f $tmpfile0 rm -f $tmpfile1 rm -f $tmpfile2 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 site.siteid = $SITEID" fi ############################################### 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'` dd=$sdd; mm=$smm; yyyy=$syyyy while true do dodate="$dd/$mm/$yyyy" tbldate=`echo $dodate | sed -e 's/\//_/g'` cdrtable="c$tbldate" #echo "dodate=$dodate cdrtable=$cdrtable dd=$dd mm=$mm yyyy=$yyyy" #echo #echo " For $dodate" # temp while cdr is stuffed at WND and BCR # rjs 28/05/2004 - 0 call cost for WND (BUT INCLUDE EQUIP COSTS) # 0 call cost for BCR if date < 15/05/2004 runisql 2>&1 <= inletno and ( (code1 <> "WND" and code1 <> "BCR") or (code1 = "BCR" and calldate >= "15/05/2004") ) union ALL select gggrid, eggrid, outletno, calldate, endtime, $cdrtable.siteid, inletno, "in", dialledno, callcategory, calltypedesc, $cdrtable.duration, $cdrtable.callcost from $cdrtable, calltypedef, site, extranges, outer $TMPSTABLE where outlettype matches "[EP]" and site.siteid = $cdrtable.siteid $SITEBIT and $cdrtable.calltype = calltypecode and outletno = $TMPSTABLE.extn and $cdrtable.siteid = $TMPSTABLE.siteid and ( ($cdrtable.calltype != "J" and $cdrtable.calltype = $TMPSTABLE.calltype) or ($cdrtable.calltype = "J" and "A" = $TMPSTABLE.calltype) ) and extranges.siteid = site.siteid and lorange <= outletno and hirange >= outletno and ( (code1 <> "WND" and code1 <> "BCR") or (code1 = "BCR" and calldate >= "15/05/2004") ) order by 1, 2, 3, 4, 5; SQLCMD cat $tmpfile1 >>$tmpfile2 rm -f $tmpfile1 # increment date variables dd=`expr $dd + 1 | awk '{printf("%02d\n",$1)}'` if [ $dd -gt `lastdayinmonth $mm $yyyy` ]; then dd=01 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 fi # break out if we are past end date if [ $yyyy$mm$dd -gt $eyyyy$emm$edd ]; then break; fi #echo done #echo #echo " End\f" # add in extension from directory to get 0 totals for extns without calls runisql 2>&1 <>$tmpfile2 # sort calls so they are in par,eggrid,extn,date,time order sort $tmpfile2 >$tmpfile0 #sed -e 's/,$//' <$tmpfile1 >>$tmpfile0 #awk -f c9.awk -F ',' -v "sdate=$SDATE" -v "edate=$EDATE" < $tmpfile0 >$tmpfile1 # send file to user #cat $tmpfile | pr_rep system cdr_ cp $tmpfile0 c9.in rm -f $tmpfile rm -f $tmpfile0 rm -f $tmpfile1 rm -f $tmpfile2 exit 0