前端之家收集整理的这篇文章主要介绍了
Shell-实际业务操作02,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/bin/sh
EXIT_FAILURE=1
EXIT_SUCCESS=0
BEGIN_TIME=`date +%s`
SCRIPT_PATH=$(cd `dirname $0`; pwd)
SCRIPT_NAME=`basename $0`
LOG_LOCATION=/ocs/tools/OperCDR/logs
VOICE_NORMAL=/bakcdr/cdrbak/VOICE/normal
VOICE_GZ_FILE=/bakcdr/cdrbak/VOICE/gz_file
DATA_NORMAL=/bakcdr/cdrbak/DATA/normal
DATA_GZ_FILE=/bakcdr/cdrbak/DATA/gz_file
SMS_NORMAL=/bakcdr/cdrbak/SMS/normal
SMS_GZ_FILE=/bakcdr/cdrbak/SMS/gz_file
TargetVoicePath=/bakcdr/cdrbak/VOICE
TargetDataPath=/bakcdr/cdrbak/DATA
TargetSmsPath=/bakcdr/cdrbak/SMS
Check_SourceMenu(){
if [ ! -d $1 ];then
echo -e "Target Menu \033[31m$1 does not exist \033[0m,existing the script \033[31m$SCRIPT_PATH/$SCRIPT_NAME\033[0m,check fisrt please" >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
exit $EXIT_FAILURE
else
cd $1
echo Current Directory $1
fi
}
Check_TargetMenu(){
if [ ! -d $1 ] ; then
mkdir -p $1
echo $1 does not exists,create successfully >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
fi
}
DealCDRFile(){
CDR_DATE=`echo $1 | awk 'BEGIN{FS="_"}{print substr($5,1,8)}'`
echo $CDR_DATE
FinalPath=$2/normal/$CDR_DATE
if [ ! -d $FinalPath ] ; then
mkdir -p $FinalPath
else
mv $1 $FinalPath
echo "$1 moved to $FinalPath successfully " >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
fi
}
Check_TargetMenu $VOICE_NORMAL
Check_TargetMenu $VOICE_GZ_FILE
Check_TargetMenu $DATA_NORMAL
Check_TargetMenu $DATA_GZ_FILE
Check_TargetMenu $SMS_NORMAL
Check_TargetMenu $SMS_GZ_FILE
SOURCE_MENU='/ocs/data/output_bak0617/251/normal/bak'
Check_SourceMenu $SOURCE_MENU
echo "==========================begin `date "+%Y-%m-%d %H:%M:%S"`===============================================" >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
for file in `ls in*.s`
do
CDR_FLAG=`echo $file | awk 'BEGIN{FS="_"}{print $3}'`
case $CDR_FLAG in
001)
DealCDRFile $file $TargetDataPath
echo Deal Data CDR $CDR_FLAG Successfully >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
;;
002)
DealCDRFile $file $TargetVoicePath
echo Deal Voice CDR $CDR_FLAG Successfully >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
;;
004)
DealCDRFile $file $TargetSmsPath
echo Deal SMS CDR $CDR_FLAG Successfully >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
;;
*)
echo -e "\033[31m ERROR $file CDR_FLAG not in 001 002 004 \033[0m" >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
;;
esac
done
END_TIME=$(date +%s)
echo "==========================end `date "+%Y-%m-%d %H:%M:%S"`=================================================" >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
echo "==========================time consuming $(($END_TIME - $BEGIN_TIME)) seconds=================================================" >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
echo "" >>$LOG_LOCATION/MvCdr4Classify.log 2>&1
exit $EXIT_SUCCESS
原文链接:https://www.f2er.com/bash/392616.html