Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3519281
  • 博文数量: 534
  • 博客积分: 11595
  • 博客等级: 上将
  • 技术积分: 5785
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-22 17:00
文章分类

全部博文(534)

文章存档

2015年(4)

2014年(27)

2013年(15)

2012年(38)

2011年(36)

2010年(85)

2009年(63)

2008年(142)

2007年(124)

分类: LINUX

2008-07-29 11:04:19

#!/bin/bash

function Usage()
{
   echo "Usage: ${0##*/} 欲分析的交易日期"
   echo "       注: 禁止对当天的实时交易日志进行分析,有可能造成系统宕机!"
   exit 1
}

#set -x
function Check_date()
{
   year=${1:0:4}
   month=${1:4:2}
   day_first=${1:6:1}
   if [ $day_first == "0" ]; then
       day=${1:7:2}
   else
       day=${1:6:2}
   fi

   cal $month $year | grep -q "\<$day" && return 1
   echo "请输入合法的日期值(格式:YYYYMMDD)"
   return 0
}

#[ $# -eq 1 ] &&  Check_date  $1 && Usage
cur_date=`date +%Y%m%d`

if [ $# -eq 1 ]; then
  Check_date  $1
  #[ $? -eq 0  -o "$cur_date" == "$1" ] && Usage
  trade_date=$1
else
  Usage
fi

log_prefix="${HOME}/log/trans/"
ebsfile="${log_prefix}ebsfs-${trade_date}.tra"
bosscfile="${log_prefix}bossc-${trade_date}.tra"
bosssfile="${log_prefix}bosss-${trade_date}.tra"

if [ -f ${ebsfile} -a ${bosscfile} -a ${bosssfile} ]; then
   :
else
   echo "${trade_date}的交易日志不存在!请指定分析日期"
   exit 1
fi

resultfile="${log_prefix}BOSS_timeout_analyse-${trade_date}.result"
if [ -f ${resultfile} ]; then
   #echo "${trade_date}充值交易BOSS超时情况分析结果文件【${resultfile}】已经存在,请直接查看!"
   more ${resultfile}
   exit 1
fi

#set -x
total=0
noreturn=0
succ=0
fail=0

echo "                   ****  $trade_date 充值交易BOSS通信超时情况分析  ****" | tee -a ${resultfile}
echo "================================================================================================" | tee -a ${resultfile}
echo -e "    充值交易BOSS流水号          代理商号码   用户号码   金额  充值时间   发送    接收    充值结果"  | tee -a ${resultfile}
#set -x

cz_total=0
cz_send_total=0
cz_recv_total=0
cz_noret_total=0
cz_succ=0

cz_serial_list=`grep "send reverse trade to boss" $ebsfile | cut -b 104-135`
for cz_serial in $cz_serial_list
do
  cz_total=`expr $cz_total + 1`
  agent=${cz_serial:4:11}
  cz_sendtime=`grep -B 1 $cz_serial $ebsfile | grep -B 1 0081500001 | sed -n 1,1p \
                  | cut -b 14-21`
  cz01_content=`grep $cz_serial $ebsfile | grep 0081500001`
  user=${cz01_content:28:11}
  money=${cz01_content:39:16}
  money=`expr $money / 100`

  cz01_content=`grep -B 1 $cz_serial $bosscfile | grep -B 1 "013201010301"`   
  if [ "CZ${cz01_content}" ==  "CZ" ]; then
     boss_sendtime="        "
     random_01=
  else
     cz_send_total=`expr $cz_send_total + 1`
     boss_sendtime=`echo "$cz01_content" | sed -n 1,1p | cut -b 14-21`
     random_01=`echo "$cz01_content" | sed -n 2,2p | cut -b 48-57`
  fi

  if [ "CZ${random_01}" ==  "CZ" ]; then
      ret01_content=
  else
      ret01_content=`grep -B 1 $random_01 $bosssfile | grep -B 1 "充值"`
  fi

  if [ "CZ${ret01_content}" ==  "CZ" ]; then
     recv_time="        "
     cz_result="BOSS未回"
  else
     cz_recv_total=`expr $cz_recv_total + 1`
     recv_time=`echo "$ret01_content" | sed -n 1,1p | cut -b 14-21`
     cz_result=`echo "$ret01_content" | sed -n 2,2p | cut -b 43-50`
     if [ "${cz_result}" == "10000000" ]; then   
        cz_result="充值成功"
        cz_succ=`expr $cz_succ + 1`
     fi
  fi
  cz_noret_total=`expr $cz_send_total - $cz_recv_total`
  
  cz02_content=`grep -B 1 $cz_serial $gdbosscfile | grep -B 1 "013601010401"`
  if [ "CZ${cz02_content}" ==  "CZ" ]; then
      random_02=
  else
      random_02=`echo "$cz02_content" | sed -n 2,2p | cut -b 49-58`
  fi
  
  if [ "CZ${random_02}" ==  "CZ" ]; then
     ret_content=
  else
     ret_content=`grep -B 1 $random_02 $gdbosssfile | grep -B 1 "冲正"`  
  fi

  if [ "CZ${ret_content}" ==  "CZ" ]; then
     result_code="BOSS未回"
  else
     result_code=`echo "$ret_content" | sed -n 2,2p | cut -b 43-50`
     [ $result_code == "10000000" ] && result_code="冲正成功"
  fi
  echo -e "$cz_serial $agent $user $money\t$cz_sendtime $boss_sendtime $recv_time $cz_result" | tee -a ${resultfile}
done
echo "================================================================================================"  | tee -a ${resultfile}
echo "BOSS超时总条数: $cz_total; 发送BOSS: $cz_send_total; BOSS应答: $cz_recv_total; BOSS未回: $cz_noret_total; BOSS成功: $cz_succ"  | tee -a ${resultfile}

set +x

阅读(1600) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~