原文件内容:

要求 如果该文件的最后一位都是1 代表文件内容正常,是成功的,如果最后一位存在0 代表失败,把失败的一行内容展示出来。
直接上代码:
riqi=`date +%Y%m%d`
arr=($(cat /rman_backup/status/upload_log/$riqi |awk -F '|' '{ print $4}'))
total=`cat /rman_backup/status/upload_log/$riqi |awk -F '|' '{ print $4}'|wc -l`
success=`cat /rman_backup/status/upload_log/$riqi |awk -F '|' '{ print $4}'|grep 1|wc -l`
if [ $total -eq $success ];then
echo "##############################复制蓝光存储校验结果##################">>/rman_backup/status/state_Sixian.log
echo "本次复制蓝光存储并校验成功!!!!" >>/rman_backup/status/state_Sixian.log
echo 1 >/rman_backup/status/languang_biaoshi
else
echo "##############################复制蓝光存储校验结果##################">>/rman_backup/status/state_Sixian.log
echo "本次复制蓝光存储校验失败!!!请重新复制并联系管理员!!!!!!!" >>/rman_backup/status/state_Sixian.log
echo 0 >/rman_backup/status/languang_biaoshi
fi
for(( i=0;i<$total;i++)) do
if [ ${arr[i]} == 0 ];then
c=`expr ${i} + 1`
echo "判断/rman_backup/status/upload_log/$riqi 文件中的 第 $c 行传输失败!!!!文件内容为:" `sed -n ${c}p /rman_backup/status/upload_log/$riqi` >>/rman_backup/status/state_Sixian.log
fi
done;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30345407/viewspace-2694580/ ,如需转载,请注明出处,否则将追究法律责任。