以下脚本是在做一个稽核任务的时候写的项目代码,暂时作为参考。
功能是遍历指定目录下指定文件名称的文件是否存在于该目录,并列出文件列表和大小。仅供参考,其中用到数组,for, if else ,case 等各种控制语句,做一个综合应用shell脚本的实例,初学的脚本,比较抠脚,哈哈。
#!/bin/bash
FILEDIR=/jzcj1/Ndata/VOLTE/VLT_SCP #此目录为主进程目录
FILEDIR_M=/jzcj3/Ndata/VOLTE/VLT_SCP #此目录为保障进程的目录,也要检查
FIVE_DAYS_AGO=`date +%Y%m%d -d'5 day ago'`
YESTERDAY=`date +%Y%m%d -d'1 day ago'`
TODAY=`date +%Y%m%d `
#工作路径
RT_PATH=/home/jzcj/user/zhf/VOLTE_AUDIT
DATE_PATH=$RT_PATH/$YESTERDAY
LOG_PATH=LOG
EXEC_LOG="$DATE_PATH/$LOG_PATH/EXEC.log"
COUNT_DETAIL_LOG="$DATE_PATH/$LOG_PATH/COUNT_DETAIL_LOG.log"
BOSS_FILE_PATH=BOSSFILE
#----------------------------------------------------定义文件前缀-----------------------------------------------------
#ID 列表
ID_581='581' #vpn home dance + voltevpn voltehome voltedance
ID_591='591' #vpn home dance
ID_592='592' #vpn home dance + voltevpn voltehome voltedance
ID_596='596' #vpn home dance
ID_597='597' #vpn home dance + voltevpn voltehome voltedance
ID_598='598' #vpn home dance + voltevpn voltehome voltedance
ID_600='600' #vpn home dance + voltevpn voltehome voltedance
ID_TD='TD' #tdcell tdvpmn
#定义文件ID数组
ID_ARR=(${ID_581} ${ID_592} ${ID_597} ${ID_598} ${ID_600} ${ID_591} ${ID_596} ${ID_TD})
#定义文件类型数组
volte=("vpn" "home" "dance" "voltevpn" "voltehome" "voltedance")
vpn_hm=("vpn" "home" "dance")
tdvp=("tdcell" "tdvpmn")
#定义文件前缀数组
FILEHEAD_UNL=() #.unl文件记录数原始通用文件前缀
FILEHEAD_TOT=() #文件记录数列表目标文件
FILEHEAD_CNT=() #统计文件记录数条数
function SetFilePreFix()
{
let ct=0
for loop in $*
do
case ${loop} in
#部分ID
${ID_591}|${ID_596}) #${ID_591}|${ID_596}
#for循环赋值数组
for i in ${vpn_hm[*]}
do
FILEHEAD_UNL[ct]=${i}${YESTERDAY}_${loop}
FILEHEAD_TOT[ct]=${i}_BOSStotal${loop}_$YESTERDAY
FILEHEAD_CNT[ct]=${i}_BOSScount${loop}_$YESTERDAY
echo "loop = $loop-------------------">>$EXEC_LOG
echo "FILEHEAD_UNL[$ct] = ${FILEHEAD_UNL[$ct]}">>$EXEC_LOG
echo "FILEHEAD_TOT[$ct] = ${FILEHEAD_TOT[$ct]}">>$EXEC_LOG
echo "FILEHEAD_CNT[$ct] = ${FILEHEAD_CNT[$ct]}">>$EXEC_LOG
let ct+=1
done
;;
#volte 全部ID
${ID_581}|${ID_592}|${ID_597}|${ID_598}|${ID_600})
#for循环赋值数组
for i in ${volte[*]}
do
FILEHEAD_UNL[ct]=${i}${YESTERDAY}_${loop}
FILEHEAD_TOT[ct]=${i}_BOSStotal${loop}_$YESTERDAY
FILEHEAD_CNT[ct]=${i}_BOSScount${loop}_$YESTERDAY
echo "loop = $loop-------------------">>$EXEC_LOG
echo "FILEHEAD_UNL[$ct] = ${FILEHEAD_UNL[$ct]}">>$EXEC_LOG
echo "FILEHEAD_TOT[$ct] = ${FILEHEAD_TOT[$ct]}">>$EXEC_LOG
echo "FILEHEAD_CNT[$ct] = ${FILEHEAD_CNT[$ct]}">>$EXEC_LOG
let ct+=1
done
;;
#tdcell tdvpmn
${ID_TD}) #
#for循环赋值数组
for i in ${tdvp[*]} #
do
FILEHEAD_UNL[ct]=${i}${YESTERDAY}
FILEHEAD_TOT[ct]=${i}_BOSStotal_$YESTERDAY
FILEHEAD_CNT[ct]=${i}_BOSScount_$YESTERDAY
echo "loop = $loop-------------------">>$EXEC_LOG
echo "FILEHEAD_UNL[$ct] = ${FILEHEAD_UNL[$ct]}">>$EXEC_LOG
echo "FILEHEAD_TOT[$ct] = ${FILEHEAD_TOT[$ct]}">>$EXEC_LOG
echo "FILEHEAD_CNT[$ct] = ${FILEHEAD_CNT[$ct]}">>$EXEC_LOG
let ct+=1
done
;;
*)
echo "Invalid ID: $loop">>$EXEC_LOG
esac
done
}
#更新目录
function UpdateDirectory()
{
cd $RT_PATH
#删除5天前的目录
if [ -d "$FIVE_DAYS_AGO" ];
then
rm -r $RT_PATH/$FIVE_DAYS_AGO
fi
#创建当前的的文件目录
if [ ! -d "$YESTERDAY" ];
then
mkdir -p $DATE_PATH
if [ $? != 0 ]
then
echo '$YESTERDAY path or sub path create failed'>>$EXEC_LOG
fi
fi
#创建内层目录
mkdir -p $DATE_PATH
mkdir -p $DATE_PATH/$LOG_PATH
mkdir -p $DATE_PATH/$BOSS_FILE_PATH
}
function ListTotal2Files()
{
let COUNT=0
let TOTAL=0
echo '-------------------------------生成中间UNL文件--------------------------'>>$EXEC_LOG
for loop in ${FILEHEAD_UNL[*]} #${FILEHEAD_UNL[*]} #"home$YESTERDAY" "dance$YESTERDAY" "volte"
do
TXT="$DATE_PATH/${loop}.txt"
UNL="$DATE_PATH/${loop}.unl"
TOTAL=0
COUNT=0
for DIR in $* #两个目录,主 ,保障
do
cd $DIR
LS_FILE=`ls -lrt ${loop}* 2>/dev/null`
if [ $? != 0 ]
then
echo "${loop}*.unl NOT EXIST">>$EXEC_LOG
fi
echo "------------------------Curret Dir is:$DIR List Files -----------------------">>$EXEC_LOG
#统计话单文件名和大小保存到临时TXT文件
echo "$LS_FILE">>$EXEC_LOG
WC_L=`ls -lrt ${loop}* 2>/dev/null | wc -l`
COUNT=${WC_L}
#echo "${loop}* file number is $COUNT">>$EXEC_LOG
if (( COUNT != 0 ))
then
#echo "----------------$DIR/-- ${loop}* file number is $COUNT">>$EXEC_LOG
echo "$LS_FILE">>$TXT #必须要以追加的方式,因为文件可能存在于两个目录
else
echo "----------------$DIR/-- ${loop}* file NOT EXIST">>$EXEC_LOG
fi
((TOTAL+=COUNT))
done
cd $DATE_PATH #返回工作目录
echo "$DIR-->${loop}* proc ->TXT end">>$EXEC_LOG
echo "${loop}* total cdr number is : $TOTAL">>$EXEC_LOG
if (( TOTAL!=0 ))
then
#有文件才生成中间UNL文件
AWK_FILE1=`awk -v FS=' ' -v OFS='|' '{print $9, $5}' $TXT |sort| uniq -u`
echo "$AWK_FILE1">>$UNL
else
#echo "${loop}.unl NOT EXIST">>$EXEC_LOG
echo "${loop}.unl NOT EXIST">>NOT_EXIST.log
fi
echo "${loop}*--> NUM = $TOTAL"
echo "*"
echo "${loop}*--> NUM = $TOTAL">>$COUNT_DETAIL_LOG
echo "*">>$COUNT_DETAIL_LOG
sleep 1
done
}
#重命名.unl文件
function ObjectCountFiles() #
{
cd $DATE_PATH
#获取数组长度 ${#arr[*]}
for (( i=0; i<${#FILEHEAD_UNL[*]} ; i++ )) #${#FILEHEAD_UNL[*]}
do
echo "F-----------------------------${FILEHEAD_UNL[$i]}.unl--------------------------------">>$EXEC_LOG
if [ -f "${FILEHEAD_UNL[$i]}.unl" ]
then
echo "MOVE ${FILEHEAD_UNL[$i]}.unl ----> ${FILEHEAD_CNT[$i]}.unl">>$EXEC_LOG
mv ${FILEHEAD_UNL[$i]}.unl ${FILEHEAD_CNT[$i]}.unl
else
echo "${FILEHEAD_UNL[$i]}.unl not exist">>$EXEC_LOG
fi
echo "------------------------------${FILEHEAD_UNL[$i]}.unl-------------------------------F">>$EXEC_LOG
done
}
#重命名total.unl文件
function ObjectTotalFiles()
{
let CNT=0
cd $DATE_PATH
#文件重命名完成后,再统计文件列表数
echo "----------------------------生成目标 TOTAL文件--------------------------">>$EXEC_LOG
for (( i=0; i<${#FILEHEAD_UNL[*]} ; i++ )) #${#FILEHEAD_UNL[*]}
do
if [ -f "${FILEHEAD_CNT[$i]}.unl" ]
then
CNT=`cat ${FILEHEAD_CNT[$i]}.unl | wc -l`
else
#没有统计到,填0
echo "${FILEHEAD_UNL[$i]}.unl NOT EXIST" >>NULL.log
((CNT = 0))
fi
#将值填入
echo "------------------------------${FILEHEAD_TOT[$i]}.unl is ${CNT}-------------------------------F">>$EXEC_LOG
echo " ${CNT}" >${FILEHEAD_TOT[$i]}.unl #前面添加4个空格
done
}
function MoveOtherFiles()
{
echo 'Move TEMP LOG ...'>>$EXEC_LOG
mv *.txt $LOG_PATH
mv *.log $LOG_PATH
mv *.unl $BOSS_FILE_PATH
echo 'All Files Operation End'>>$EXEC_LOG
}
#先更新目录
UpdateDirectory
echo "---------------------------------------------------------更新目录-------------------------------------------------------------">>$COUNT_DETAIL_LOG
echo "---------------------------------------------------------更新目录-------------------------------------------------------------"
#确认每种文件的前缀
echo "---------------------------------------------------------文件前缀-------------------------------------------------------------">>$COUNT_DETAIL_LOG
echo "---------------------------------------------------------文件前缀-------------------------------------------------------------"
SetFilePreFix ${ID_ARR[*]} #数组作为参数传递 ${arr[*]}
#主进程目录和保障进程目录作为输入参数,统计两个目录下的文件数
echo "---------------------------------------------------------统计文件-------------------------------------------------------------">>$COUNT_DETAIL_LOG
echo "---------------------------------------------------------统计文件-------------------------------------------------------------"
ListTotal2Files $FILEDIR $FILEDIR_M
#生成count文件
echo "---------------------------------------------------------COUNT文件生成-------------------------------------------------------------">>$COUNT_DETAIL_LOG
echo "---------------------------------------------------------COUNT文件生成-------------------------------------------------------------"
ObjectCountFiles
#生成total文件
echo "---------------------------------------------------------TOTAL文件生成-------------------------------------------------------------">>$COUNT_DETAIL_LOG
echo "---------------------------------------------------------TOTAL文件生成-------------------------------------------------------------"
ObjectTotalFiles
#转移log文件
echo "---------------------------------------------------------转移临时文件-------------------------------------------------------------">>$COUNT_DETAIL_LOG
echo "---------------------------------------------------------转移临时文件-------------------------------------------------------------"
MoveOtherFiles
生成的统计文件如下,内容是: 文件名|文件大小
以下脚本是配合上面的脚本的,作用是对服务器获取的文件列表,大小与本地的文件列表,大小。
参考对比部分即可
#!/bin/bash
FILEDIR=/jzcj1/Ndata/VOLTE/VLT_SCP #此目录为主进程目录
FILEDIR_M=/jzcj3/Ndata/VOLTE/VLT_SCP #此目录为保障进程的目录,也要检查
FIVE_DAYS_AGO=`date +%Y%m%d -d'5 day ago'`
YESTERDAY=`date +%Y%m%d -d'1 day ago'`
TODAY=`date +%Y%m%d `
#工作路径
RT_PATH=/home/jzcj/user/zhf/VOLTE_AUDIT
DATE_PATH=$RT_PATH/$YESTERDAY
COMP_COMM_PATH=$DATE_PATH/COMP
PATH_DIFF=$COMP_COMM_PATH/DIFF
LOG_PATH=$COMP_COMM_PATH/LOG
BOSS_FILE_PATH=$DATE_PATH/BOSSFILE
LOCAL_ZNW_FILE_PATH=$DATE_PATH/ZNWFILE
COMP_LOG="$LOG_PATH/COMP.log"
#以下3个目录为差异文件目录
PATH_NO_NETS=$COMP_COMM_PATH/NO_NETS
PATH_NO_BOSS=$COMP_COMM_PATH/NO_BOSS
PATH_NO_BOTH=$COMP_COMM_PATH/NO_BOTH
#更新目录
function UpdateDirectory()
{
cd $RT_PATH
#创建当前的的文件目录
if [ ! -d "$DATE_PATH" ];
then
mkdir -p $DATE_PATH
if [ $? != 0 ]
then
echo '$DATE_PATH path or sub path create failed'>>$COMP_LOG
fi
fi
#创建内层目录
mkdir -p $COMP_COMM_PATH
mkdir -p $PATH_DIFF
mkdir -p $LOG_PATH
mkdir -p $BOSS_FILE_PATH
mkdir -p $LOCAL_ZNW_FILE_PATH
mkdir -p $PATH_NO_BOTH
mkdir -p $PATH_NO_NETS
mkdir -p $PATH_NO_BOSS
}
#----------------------------------------------------定义文件前缀-----------------------------------------------------
#ID 列表
ID_581='581' #vpn home dance + voltevpn voltehome voltedance
ID_591='591' #vpn home dance
ID_592='592' #vpn home dance + voltevpn voltehome voltedance
ID_596='596' #vpn home dance
ID_597='597' #vpn home dance + voltevpn voltehome voltedance
ID_598='598' #vpn home dance + voltevpn voltehome voltedance
ID_600='600' #vpn home dance + voltevpn voltehome voltedance
ID_TD='TD' #tdcell tdvpmn
#定义文件ID数组
ID_ARR=(${ID_581} ${ID_592} ${ID_597} ${ID_598} ${ID_600} ${ID_591} ${ID_596} ${ID_TD})
#定义文件类型数组
volte=("vpn" "home" "dance" "voltevpn" "voltehome" "voltedance")
vpn_hm=("vpn" "home" "dance")
tdvp=("tdcell" "tdvpmn")
#定义BOSS 侧文件前缀数组
BOSS_FILEHEAD_UNL=() #.unl文件记录数原始通用文件前缀
BOSS_FILEHEAD_TOT=() #文件记录数列表目标文件
BOSS_FILEHEAD_CNT=() #统计文件记录数条数
function SetBOSS_FilePreFix()
{
let ct=0
for loop in $*
do
case ${loop} in
#部分ID
${ID_591}|${ID_596}) #${ID_591}|${ID_596}
#for循环赋值数组
for i in ${vpn_hm[*]}
do
BOSS_FILEHEAD_UNL[ct]=${i}${YESTERDAY}_${loop}
BOSS_FILEHEAD_TOT[ct]=${i}_BOSStotal${loop}_$YESTERDAY
BOSS_FILEHEAD_CNT[ct]=${i}_BOSScount${loop}_$YESTERDAY
echo "loop = $loop-------------------">>$COMP_LOG
echo "BOSS_FILEHEAD_UNL[$ct] = ${BOSS_FILEHEAD_UNL[$ct]}">>$COMP_LOG
echo "BOSS_FILEHEAD_TOT[$ct] = ${BOSS_FILEHEAD_TOT[$ct]}">>$COMP_LOG
echo "BOSS_FILEHEAD_CNT[$ct] = ${BOSS_FILEHEAD_CNT[$ct]}">>$COMP_LOG
let ct+=1
done
;;
#volte 全部ID
${ID_581}|${ID_592}|${ID_597}|${ID_598}|${ID_600})
#for循环赋值数组
for i in ${volte[*]}
do
BOSS_FILEHEAD_UNL[ct]=${i}${YESTERDAY}_${loop}
BOSS_FILEHEAD_TOT[ct]=${i}_BOSStotal${loop}_$YESTERDAY
BOSS_FILEHEAD_CNT[ct]=${i}_BOSScount${loop}_$YESTERDAY
echo "loop = $loop-------------------">>$COMP_LOG
echo "BOSS_FILEHEAD_UNL[$ct] = ${BOSS_FILEHEAD_UNL[$ct]}">>$COMP_LOG
echo "BOSS_FILEHEAD_TOT[$ct] = ${BOSS_FILEHEAD_TOT[$ct]}">>$COMP_LOG
echo "BOSS_FILEHEAD_CNT[$ct] = ${BOSS_FILEHEAD_CNT[$ct]}">>$COMP_LOG
let ct+=1
done
;;
#tdcell tdvpmn
${ID_TD}) #
#for循环赋值数组
for i in ${tdvp[*]} #
do
BOSS_FILEHEAD_UNL[ct]=${i}${YESTERDAY}
BOSS_FILEHEAD_TOT[ct]=${i}_BOSStotal_$YESTERDAY
BOSS_FILEHEAD_CNT[ct]=${i}_BOSScount_$YESTERDAY
echo "loop = $loop-------------------">>$COMP_LOG
echo "BOSS_FILEHEAD_UNL[$ct] = ${BOSS_FILEHEAD_UNL[$ct]}">>$COMP_LOG
echo "BOSS_FILEHEAD_TOT[$ct] = ${BOSS_FILEHEAD_TOT[$ct]}">>$COMP_LOG
echo "BOSS_FILEHEAD_CNT[$ct] = ${BOSS_FILEHEAD_CNT[$ct]}">>$COMP_LOG
let ct+=1
done
;;
*)
echo "Invalid ID: $loop">>$COMP_LOG
esac
done
}
#定义NET 侧文件前缀数组
ZNW_FILEHEAD_UNL=() #.unl文件记录数原始通用文件前缀
ZNW_FILEHEAD_TOT=() #文件记录数列表目标文件
ZNW_FILEHEAD_CNT=() #统计文件记录数条数
function SetZNW_FilePreFix()
{
let ct=0
for loop in $*
do
case ${loop} in
#部分ID
${ID_591}|${ID_596}) #${ID_591}|${ID_596}
#for循环赋值数组
for i in ${vpn_hm[*]}
do
ZNW_FILEHEAD_UNL[ct]=${i}${YESTERDAY}_${loop}
ZNW_FILEHEAD_TOT[ct]=${i}_ZNWtotal${loop}_$YESTERDAY
ZNW_FILEHEAD_CNT[ct]=${i}_ZNWcount${loop}_$YESTERDAY
echo "loop = $loop-------------------">>$COMP_LOG
echo "ZNW_FILEHEAD_UNL[$ct] = ${ZNW_FILEHEAD_UNL[$ct]}">>$COMP_LOG
echo "ZNW_FILEHEAD_TOT[$ct] = ${ZNW_FILEHEAD_TOT[$ct]}">>$COMP_LOG
echo "ZNW_FILEHEAD_CNT[$ct] = ${ZNW_FILEHEAD_CNT[$ct]}">>$COMP_LOG
let ct+=1
done
;;
#volte 全部ID
${ID_581}|${ID_592}|${ID_597}|${ID_598}|${ID_600})
#for循环赋值数组
for i in ${volte[*]}
do
ZNW_FILEHEAD_UNL[ct]=${i}${YESTERDAY}_${loop}
ZNW_FILEHEAD_TOT[ct]=${i}_ZNWtotal${loop}_$YESTERDAY
ZNW_FILEHEAD_CNT[ct]=${i}_ZNWcount${loop}_$YESTERDAY
echo "loop = $loop-------------------">>$COMP_LOG
echo "ZNW_FILEHEAD_UNL[$ct] = ${ZNW_FILEHEAD_UNL[$ct]}">>$COMP_LOG
echo "ZNW_FILEHEAD_TOT[$ct] = ${ZNW_FILEHEAD_TOT[$ct]}">>$COMP_LOG
echo "ZNW_FILEHEAD_CNT[$ct] = ${ZNW_FILEHEAD_CNT[$ct]}">>$COMP_LOG
let ct+=1
done
;;
#tdcell tdvpmn
${ID_TD}) #
#for循环赋值数组
for i in ${tdvp[*]} #
do
ZNW_FILEHEAD_UNL[ct]=${i}${YESTERDAY}
ZNW_FILEHEAD_TOT[ct]=${i}_ZNWtotal_$YESTERDAY
ZNW_FILEHEAD_CNT[ct]=${i}_ZNWcount_$YESTERDAY
echo "loop = $loop-------------------">>$COMP_LOG
echo "ZNW_FILEHEAD_UNL[$ct] = ${ZNW_FILEHEAD_UNL[$ct]}">>$COMP_LOG
echo "ZNW_FILEHEAD_TOT[$ct] = ${ZNW_FILEHEAD_TOT[$ct]}">>$COMP_LOG
echo "ZNW_FILEHEAD_CNT[$ct] = ${ZNW_FILEHEAD_CNT[$ct]}">>$COMP_LOG
let ct+=1
done
;;
*)
echo "Invalid ID: $loop">>$COMP_LOG
esac
done
}
BOSS_FILE_PATH=$DATE_PATH/BOSSFILE
LOCAL_ZNW_FILE_PATH=$DATE_PATH/ZNWFILE
function Comp_BOSS_ZNW_NUL()
{
cd $DATE_PATH
#获取数组长度 ${#arr[*]}
for (( i=0; i<${#BOSS_FILEHEAD_CNT[*]} ; i++ )) #${#BOSS_FILEHEAD_CNT[*]}
do
echo "-----------------------------对比 ${BOSS_FILEHEAD_CNT[$i]}.unl --------------------------------"
echo "-----------------------------对比 ${BOSS_FILEHEAD_CNT[$i]}.unl --------------------------------">>$COMP_LOG
echo "查看 ${LOCAL_ZNW_FILE_PATH}/ 下${ZNW_FILEHEAD_CNT[$i]}.unl :"
echo "查看 ${LOCAL_ZNW_FILE_PATH}/ 下${ZNW_FILEHEAD_CNT[$i]}.unl :">>$COMP_LOG
cd $LOCAL_ZNW_FILE_PATH/
echo `pwd`
echo `pwd`>>$COMP_LOG
LS_ZNW=`ls ${ZNW_FILEHEAD_CNT[$i]}.unl`
echo ${LS_ZNW}
echo ${LS_ZNW}>>$COMP_LOG
echo "查看 ${BOSS_FILE_PATH}/ 下${BOSS_FILEHEAD_CNT[$i]}.unl :"
echo "查看 ${BOSS_FILE_PATH}/ 下${BOSS_FILEHEAD_CNT[$i]}.unl :">>$COMP_LOG
cd $BOSS_FILE_PATH/
echo `pwd`>>$COMP_LOG
echo `pwd`
LS_BOSS=`ls ${BOSS_FILEHEAD_CNT[$i]}.unl`
echo ${LS_BOSS}
echo ${LS_BOSS}>>$COMP_LOG
cd $DATE_PATH
echo `pwd`
if [ -f "${BOSS_FILE_PATH}/${BOSS_FILEHEAD_CNT[$i]}.unl" ] && [ -f "${LOCAL_ZNW_FILE_PATH}/${ZNW_FILEHEAD_CNT[$i]}.unl" ]
then
echo "------------------- 对比 ${BOSS_FILEHEAD_CNT[$i]}.unl ## ${ZNW_FILEHEAD_CNT[$i]}.unl -------------------"
echo "------------------- 对比 ${BOSS_FILEHEAD_CNT[$i]}.unl ## ${ZNW_FILEHEAD_CNT[$i]}.unl -------------------">>$COMP_LOG
#排序两个文件到临时文件
sort -u $LOCAL_ZNW_FILE_PATH/${ZNW_FILEHEAD_CNT[$i]}.unl>$LOCAL_ZNW_FILE_PATH/${ZNW_FILEHEAD_CNT[$i]}.S
sleep 1
sort -u $BOSS_FILE_PATH/${BOSS_FILEHEAD_CNT[$i]}.unl>$BOSS_FILE_PATH/${BOSS_FILEHEAD_CNT[$i]}.S
#比较排序后的文件,显示在网元侧存在而在BOSS侧不存在的行
comm -23 $LOCAL_ZNW_FILE_PATH/${ZNW_FILEHEAD_CNT[$i]}.S $BOSS_FILE_PATH/${BOSS_FILEHEAD_CNT[$i]}.S >$PATH_DIFF/${ZNW_FILEHEAD_CNT[$i]}_${BOSS_FILEHEAD_CNT[$i]}.DIFF
let T=0
T=$(cat $PATH_DIFF/${ZNW_FILEHEAD_CNT[$i]}_${BOSS_FILEHEAD_CNT[$i]}.DIFF | wc -l)
echo "-----------------------------对比差异的结果有$T行 --------------------------------"
echo "-----------------------------对比差异的结果有$T行 --------------------------------">>$COMP_LOG
if (( T==0))
then
#对比无差异,转移DIFF文件备份
mv $PATH_DIFF/${ZNW_FILEHEAD_CNT[$i]}_${BOSS_FILEHEAD_CNT[$i]}.DIFF $LOG_PATH
else
#有差异的文件要保留在DIFF供查询
cp $PATH_DIFF/${ZNW_FILEHEAD_CNT[$i]}_${BOSS_FILEHEAD_CNT[$i]}.DIFF $LOG_PATH
fi
#删除临时S文件
rm -f $LOCAL_ZNW_FILE_PATH/${ZNW_FILEHEAD_CNT[$i]}.S
rm -f $BOSS_FILE_PATH/${BOSS_FILEHEAD_CNT[$i]}.S
elif [ -f ${BOSS_FILE_PATH}/"${BOSS_FILEHEAD_CNT[$i]}.unl" ] && [ ! -f "${LOCAL_ZNW_FILE_PATH}/${ZNW_FILEHEAD_CNT[$i]}.unl" ]
then
#BOSS 侧有文件,ZNW侧无文件
echo "${ZNW_FILEHEAD_CNT[$i]}.unl NOT EXIST">$PATH_NO_NETS/${ZNW_FILEHEAD_CNT[$i]}_${BOSS_FILEHEAD_CNT[$i]}.NO_NETS
elif [ ! -f ${BOSS_FILE_PATH}/"${BOSS_FILEHEAD_CNT[$i]}.unl" ] && [ -f "${LOCAL_ZNW_FILE_PATH}/${ZNW_FILEHEAD_CNT[$i]}.unl" ]
then
#BOSS 侧无文件,ZNW有无文件
echo "${BOSS_FILEHEAD_CNT[$i]}.unl NOT EXIST">$PATH_NO_BOSS/${ZNW_FILEHEAD_CNT[$i]}_${BOSS_FILEHEAD_CNT[$i]}.NO_BOSS
else
#两侧都无文件
echo "${BOSS_FILEHEAD_CNT[$i]}.unl AND ${ZNW_FILEHEAD_CNT[$i]}.unl BOTH NOT EXIST">$PATH_NO_BOTH/${ZNW_FILEHEAD_CNT[$i]}_${BOSS_FILEHEAD_CNT[$i]}.NO_BOTH
fi
done
}
#更新目录
echo '--------------------------COMP------------------------更新目录--------------------------COMP------------------------'
UpdateDirectory
#设置BOSS文件前缀数组
echo '--------------------------COMP------------------------设置BOSS文件前缀--------------------------COMP------------------------'
SetBOSS_FilePreFix ${ID_ARR[*]} #数组作为参数传递 ${arr[*]}
#设置ZNW文件前缀数组
echo '--------------------------COMP------------------------设置ZNW文件前缀数组--------------------------COMP------------------------'
SetZNW_FilePreFix ${ID_ARR[*]} #数组作为参数传递 ${arr[*]}
#对比文件 核心功能
echo '--------------------------COMP------------------------设置ZNW文件前缀数组--------------------------COMP------------------------'
Comp_BOSS_ZNW_NUL