投递文章投递文章 投稿指南 RSS订阅RSS订阅

话单比对统一解决方案(基于Shell)

来源:cnblogs yijiyong100 发布时间:2009-03-13 收藏 投稿 字体:【
在外实习,除了工作,自己还可以做一些感兴趣的事情,这段时间一致在做话单比对的工作,最近又在数据中心的比对,哎呀除了核对还是核对,真是单调!

    为什么了不做一个全自动的核对机了,就像全自动的洗衣机你把洗衣粉放好了,水龙头打开,设定一个模式,他自己就会洗、漂、脱一体服务。

    嘿嘿,我这两天断断续续做的这个解决方案就是基于这个想法哦,是不是很帅哦....

##################### Uniform Solution for Bill Comparison ################################
##################### Date: 2009-3-6  #####################################################
##################### Author: landry yi  ##################################################
##################### Email: yijiyong100@163.com  #########################################
##################### Copyright: Harbin Normal University@copyright2009 ###################
##################### Version: 1.0.0#######################################################
##################### Histroy: if modified ,please add here and release new veresion#######

############## Config Part ################################################################
SystemBak="/transfer/yijy/cmp_shell/bak"
SystemTmp="/transfer/yijy/cmp_shell/tmp"
SystemLog="/transfer/yijy/cmp_shell/log"
SystemErr="/transfer/yijy/cmp_shell/err"

NewDataSourceDir="/transfer/yijy/cmp_shell/bin/vtof/bak"
NewDataSourceExp="*20090101*"
OldDataSourceDir="/transfer/yijy/cmp_shell/bin/vtof/bak"
OldDataSourceExp="*20090101*"

NewConvertFlag="on"
NewConvertBinDir="/transfer/yijy/cmp_shell/bin/vtof/new/vtof1"
NewConvertBinCfg="/transfer/yijy/cmp_shell/bin/vtof/cfg/new/vtof.cfg"
NewConvertBinIn="/transfer/yijy/cmp_shell/bin/vtof/new/in"
NewConvertBinOut="/transfer/yijy/cmp_shell/bin/vtof/new/out"
NewConvertSplit="|"

OldConvertFlag="on"
OldConvertBinDir="/transfer/yijy/cmp_shell/bin/vtof/old/vtof1"
OldConvertBinCfg="/transfer/yijy/cmp_shell/bin/vtof/cfg/old/vtof.cfg"
OldConvertBinIn="/transfer/yijy/cmp_shell/bin/vtof/old/in"
OldConvertBinOut="/transfer/yijy/cmp_shell/bin/vtof/old/out"
OldConvertSplit="|"

NewCmpExtractFlag="on"
NewCmpExtractKey="1,3,6,8,10"
NewCmpExtractSem="msisdn:2,chat_type:11,fee_type:16,fee1:14,old_fee1:2"
OldCmpExtractFlag="on"
OldCmpExtractKey="1,3,6,8,10"
OldCmpExtractSem="msisdn:2,chat_type:11,fee_type:16,fee1:14,old_fee1:2"

NewCmpFilePrex="new."
OldCmpFilePrex="old."

CmpFileNewIn="/transfer/yijy/cmp_shell/cmp/new/new_in"
CmpFileOldIn="/transfer/yijy/cmp_shell/cmp/new/old_in"
CmpBinDir="/transfer/yijy/cmp_shell/cmp/bin/o2n_cmp"
CmpBinCfg="/transfer/yijy/cmp_shell/cmp/cfg/wa.cfg"

CheckFile()
{
    if [  ! -d ${SystemBak}  -o  ! -d ${SystemTmp}  -o  ! -d ${CmpFileNewIn}  -o  ! -d ${CmpFileOldIn}  ]
    then
          echo 'APP:ERROR:Config error -- DIR'
          exit
    fi
    if [ ! -d ${SystemLog} -o ! -d ${SystemErr} ]
    then
          echo 'APP:ERROR:Config error -- System Dir'
          exit
    fi
    if [ ! -d ${NewConvertBinIn} -o ! -d ${NewConvertBinOut} -o ! -d ${OldConvertBinIn} -o ! -d ${OldConvertBinOut} ]
    then
           echo 'APP:ERROR:Convert error -- DIR'
           exit
    fi
    if [ ! -f $CmpBinDir -o ! -f $CmpBinCfg ]
    then
          echo 'APP:ERROR:Config error -- FILE'
          exit
    fi
    if [ ! -d $NewDataSourceDir -o ! -d $OldDataSourceDir ]
    then 
          echo 'APP:ERROR:Config error -- Datasource'
          exit
    fi
    if [ ! ${NewConvertSplit} -o ! ${OldConvertSplit} ]
    then
          echo 'APP:ERROR:Config error -- ConvertSplitchar  can not be NULL'
          exit
    fi
    if [ ! $NewDataSourceExp -o ! $OldDataSourceExp ]
    then
          echo 'APP:ERROR:Config error -- DataSourceExp can not be NULL'
          exit
    fi
    if [ $NewConvertFlag = "on" ]
    then
          if [ ! -d ${NewConvertBinIn} -o ! -d ${NewConvertBinOut} -o ! -f ${NewConvertBinDir} -o ! -f ${NewConvertBinCfg} ]
          then
             echo 'APP:ERROR:Config error -- NewConvert'
             exit
          fi
    fi
    if [ $OldConvertFlag = "on" ]
    then
          if [ ! -d ${OldConvertBinIn} -o ! -d ${OldConvertBinOut} -o ! -f ${OldConvertBinDir} -o ! -f ${OldConvertBinCfg} ]
          then 
             echo 'APP:ERROR:Config error -- OldConvert'
             exit
          fi
    fi
    if [ ! $NewCmpFilePrex -o ! $OldCmpFilePrex ]
    then
          echo 'APP:ERROR:Config error -- prex'
          exit
    fi
    if [ -n ${NewCmpExtractKey} -a -n ${NewCmpExtractSem} -a -n ${OldCmpExtractKey} -a -n ${OldCmpExtractSem} ]
    then
           echo ${NewCmpExtractKey} | awk -F ',' '{ 
             printf("APP:MSG:NewExkey number is [%d] -- and the New key are [%s]\n",NF,$0);
           }'
           echo ${NewCmpExtractSem} | awk -F ',' '{
             NewExsemNum=NF
             printf("APP:MSG:NewExsem number is [%d] -- and the New sem are [%s]\n",NF,$0);
           }' 
           echo ${OldCmpExtractKey} | awk -F ',' '{
             OldExkeyNum=NF
             printf("APP:MSG:OldExkey number is [%d] -- and the Old key are [%s]\n",NF,$0);
           }'
           echo ${OldCmpExtractSem} | awk -F ',' '{
             OldExsemNum=NF
             printf("APP:MSG:OldExsem number is [%d] -- and the Old sem are [%s]\n",NF,$0);
           }'
           newExtractKeyNumber=`echo ${NewCmpExtractKey} | awk -F ',' '{printf("%d",NF)}'`
           newExtractSemNumber=`echo ${NewCmpExtractSem} | awk -F ',' '{printf("%d",NF)}'`
           if [ ${newExtractKeyNumber} -ne ${newExtractSemNumber} ]
           then
                echo 'APP:ERROR:The new extract key number not equal to sem number'
                exit
           fi
           oldExtractKeyNumber=`echo ${OldCmpExtractKey} | awk -F ',' '{printf("%d",NF)}'`          
           oldExtractSemNumber=`echo ${OldCmpExtractSem} | awk -F ',' '{printf("%d",NF)}'`
           if [ ${oldExtractKeyNumber} -ne ${oldExtractSemNumber} ]
           then
                echo 'APP:ERROR:The old extract key number not equal to sem number'
                exit
           fi
    else
          echo 'APP:ERROR:Config error -- Extract'
          exit  
    fi         
    echo 'APP:MSG:Config part check successful!'
}

############## Clean Enviroment ###########################################################
CleanEnviroment()
{
  echo 'APP:MSG:Start clean the system enviroment...'
  ########### <--add your own script here to clean the enviroment if you like--> ##########


  ########### <--add your own script here to clean the enviroment if you like--> ##########
  echo 'APP:MSG:Clean the system enviroment over...'
}

############## Data Prepare ###############################################################
totalNewConvertIn=0
totalOldConvertIn=0
totalNewExtractIn=0
totalOldExtractIn=0
DataPrepare()
{
    if [ ! -d ${NewDataSourceDir} -o ! -d ${OldDataSourceDir} ]
    then
         echo 'APP:ERROR:Data source error'
         exit
    fi
    echo 'APP:MSG:Data start prepare...'
    if [ ${NewConvertFlag} = "on" ]
    then
         cp -r ${NewDataSourceDir}/${NewDataSourceExp} ${NewConvertBinIn}
         let totalNewConvertIn=`ls -1 ${NewConvertBinIn} | wc -l`
         echo 'APP:MSG:The total number of new file need convert in ['${NewConvertBinIn}'] is ['${totalNewConvertIn}']'
    else
         cp -r ${NewDataSourceDir}/${NewDataSourceExp} ${NewConvertBinOut}
         let totalNewExtractIn=`ls -1 ${NewConvertBinOut} | wc -l`
         echo 'APP:MSG:The total number of new file need extract in ['${NewConvertBinOut}'] is ['${totalNewExtractIn}']'
    fi
    if [ ${OldConvertFlag} = "on" ]
    then
         cp -r ${OldDataSourceDir}/${OldDataSourceExp} ${OldConvertBinIn}
         let totalOldConvertIn=`ls -1 ${OldConvertBinIn} | wc -l`
         echo 'APP:MSG:The total number of new file need convert in ['${OldConvertBinIn}'] is ['${totalOldConvertIn}']'
    else
         cp -r ${OldDataSourceDir}/${OldDataSourceExp} ${OldConvertBinOut}
         let totalOldExtractIn=`ls -1 ${OldConvertBinOut} | wc -l`
         echo 'APP:MSG:The total number of new file need extract in ['${OldConvertBinOut}'] is ['${totalOldExtractIn}']'
    fi
    echo 'APP:MSG:Data prepare over...'
}

############## Convert Part ###############################################################
ConvertFile()  
{
    if [ ${NewConvertFlag} = "on" ]
    then
        if [ 0 -eq `ls -1 ${NewConvertBinIn} | wc -l` ]
        then
           echo 'APP:MSG:No file exist in '${NewConvertBinIn}
           exit
        else
           let totalNewConvertIn=`ls -1 ${NewConvertBinIn} | wc -l`
           newCurPercent=0
           newTmpPercent=0
           echo 'APP:MSG:Start convert new file:'
           echo 'APP:MSG:The total file number in the ['${NewConvertBinIn}'] is ['${totalNewConvertIn}']'
           echo 'APP:MSG:\c'
           nohup ${NewConvertBinDir} ${NewConvertBinCfg} & 
           sleep 1
           echo 'APP:MSG:Process Bar:____________________________________________50%_________________________________________________100%'
           echo 'APP:MSG:Convert Pro:\c'
           while [ 0 -lt `ls -1 ${NewConvertBinIn} | wc -l` ]
           do
                  newExtCurFile=`ls -1 ${NewConvertBinIn} | wc -l`
                  let NewDValue=totalNewConvertIn-newExtCurFile
                  let newCurPercent=${NewDValue}\*100/${totalNewConvertIn}
                  while [ ${newTmpPercent} -lt ${newCurPercent} ]
                  do
                           echo '#\c'
                           let newTmpPercent=newTmpPercent+1
                  done
           done
           while [ $newTmpPercent -lt 100 ]
           do
                echo '#\c'
                let newTmpPercent=newTmpPercent+1
           done
           newConvertId=`ps -ef | grep ${NewConvertBinDir} | grep ${NewConvertBinCfg} | awk '{printf("%s",$2);}'`
           echo '\nAPP:MSG:New convert program id is ['${newConvertId}']'
           kill ${newConvertId}
           echo 'APP:MSG:New convert program was killed!'
           echo 'APP:MSG:New file Convert over!'
        fi 
    fi
    if [ ${OldConvertFlag} = "on" ]
    then
        if [ 0 -eq `ls -1 ${OldConvertBinIn} | wc -l` ]
        then
           echo 'APP:MSG:No file exist in '${OldConvertBinIn}
           exit
        else
           let totalOldConvertIn=`ls -1 ${OldConvertBinIn} | wc -l`
           oldCurPercent=0
           oldTmpPercent=0
           echo 'APP:MSG:Start convert old file:'
           echo 'APP:MSG:The total file number in the ['${OldConvertBinIn}'] is ['${totalOldConvertIn}']'
           echo 'APP:MSG:\c'
           nohup ${OldConvertBinDir} ${OldConvertBinCfg} &
           sleep 1
           echo 'APP:MSG:Process Bar:____________________________________________50%_________________________________________________100%'

           echo 'APP:MSG:Convert Pro:\c'
           while [ 0 -lt `ls -1 ${OldConvertBinIn} | wc -l` ]
           do
                  oldExtCurFile=`ls -1 ${OldConvertBinIn} | wc -l`
                  let OldDValue=totalOldConvertIn-oldExtCurFile
                  let oldCurPercent=${OldDValue}\*100/${totalOldConvertIn}
                  while [ ${oldTmpPercent} -lt ${oldCurPercent} ]
                  do
                           echo '#\c'
                           let oldTmpPercent=oldTmpPercent+1
                  done
           done
           while [ $oldTmpPercent -lt 100 ]
           do
                echo '#\c'
                let oldTmpPercent=oldTmpPercent+1
           done
           oldConvertId=`ps -ef | grep ${OldConvertBinDir} | grep ${OldConvertBinCfg} | awk '{printf("%s",$2);}'`
           echo '\nAPP:MSG:Old convert program id is ['${oldConvertId}']'
           kill ${oldConvertId}
           echo 'APP:MSG:Old convert program was killed!'
           echo 'APP:MSG:Old file Convert over!'
        fi
    fi
}

顶一下
(0)
0%
踩一下
(0)
0%
本文Tags:
  • 表情:
  •    
  • 评价:
用户名: 密码: 匿名 注册
最新评论 查看所有评论
About iTtang - 联系我们  - 专题列表 - 友情链接  -  高级搜索  -  帮助中心  -  您的意见