aiupdate backup
aiupdate backup
#!/bin/bash #filename: aiupdate.sh #usage: ./aiupdate.sh DOWN_FILE="zjnineinoneipexcelout" cur_date="$( date '+%Y-%m-%d' )" ALL_SN_IP_ALL="zj-ai-sn-ip-all" ALL_SN_IP_XS="zj-ai-sn-ip-xiangshan" read -p "Download zhejiang ship list file, Are you sure you want to continue connecting (y/n) ? " choice_val if [ "$choice_val" == "y" ] then curl -s -O "http://10.0.8.182:5000/user/$DOWN_FILE" [ $( du -s $DOWN_FILE | awk '{print $1}' ) -lt 5 ] && echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "$DOWN_FILE error, will exit." && exit 0 echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "$DOWN_FILE success" mv $DOWN_FILE ${DOWN_FILE}.xlsx in2csv zjnineinoneipexcelout.xlsx >zjnineinoneipexcelout.csv 2>/dev/null [ $( du -s ${DOWN_FILE}.csv | awk '{print $1}' ) -lt 5 ] && echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "${DOWN_FILE}.csv error, will exit." && exit 0 sed -i '/^[[:space:]]*$/d' ${DOWN_FILE}.csv grep -E "设备序列号|浙江" ${DOWN_FILE}.csv | awk 'BEGIN { FS=OFS="," } {print $2,$3}' >${ALL_SN_IP_ALL}-${cur_date}.csv grep -E "设备序列号|浙象" ${DOWN_FILE}.csv | awk 'BEGIN { FS=OFS="," } {print $2,$3}' >${ALL_SN_IP_XS}-${cur_date}.csv [ $( du -s ${ALL_SN_IP_ALL}-${cur_date}.csv | awk '{print $1}' ) -lt 5 ] && echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "${ALL_SN_IP_ALL}-${cur_date}.csv error, will exit." && exit 0 [ $( du -s ${ALL_SN_IP_XS}-${cur_date}.csv | awk '{print $1}' ) -lt 5 ] && echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "${ALL_SN_IP_XS}-${cur_date}.csv error, will exit." && exit 0 sed -i '1s/设备序列号,Ip/DeviceSN,RemoteEndPoint/' ${ALL_SN_IP_ALL}-${cur_date}.csv sed -i '1s/设备序列号,Ip/DeviceSN,RemoteEndPoint/' ${ALL_SN_IP_XS}-${cur_date}.csv rm -f ${DOWN_FILE}* echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "${ALL_SN_IP_ALL} count file == " "$( wc -l ${ALL_SN_IP_ALL}-${cur_date}.csv )" echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "${ALL_SN_IP_XS} count file == " "$( wc -l ${ALL_SN_IP_XS}-${cur_date}.csv )" cp ${ALL_SN_IP_ALL}-${cur_date}.csv RecordFile/${ALL_SN_IP_ALL}.csv cp ${ALL_SN_IP_XS}-${cur_date}.csv RecordFile/${ALL_SN_IP_XS}.csv echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "in RecordFile directory generate ${ALL_SN_IP_ALL}.csv" echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "in RecordFile directory generate ${ALL_SN_IP_XS}.csv" else echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "skip down $DOWN_FILE" fi echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "process SNList_new ...." echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "need select ${ALL_SN_IP_ALL}.csv / ${ALL_SN_IP_XS}.csv and SNList_total_xiangshan.csv" cat /dev/null >SNList_new.csv ./SNHandler >/dev/null 2>&1 echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "in RecordFile directory copy SNList_null.csv to SNList.csv" [ ! -e "RecordFile/SNList_null.csv" ] && echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "in RecordFile directory SNList_null.csv non-existent, will exit." && exit 0 cp RecordFile/SNList_null.csv RecordFile/SNList.csv echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "in RecordFile directory copy IPList_null.csv to IPList.csv" [ ! -e "RecordFile/IPList_null.csv" ] && echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "in RecordFile directory IPList_null.csv non-existent, will exit." && exit 0 cp RecordFile/IPList_null.csv RecordFile/IPList.csv echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "in RecordFile directory add SNList_new.csv to IPList.csv" cat SNList_new.csv >>RecordFile/IPList.csv SNList_new_count=$(awk 'END {print NR}' SNList_new.csv) IPList_count=$(awk 'END {print NR}' RecordFile/IPList.csv) SNList_count=$(awk 'END {print NR}' RecordFile/SNList.csv) SNList_total_xiangshan_count=$(awk 'END {print NR}' RecordFile/SNList_total_xiangshan.csv) echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "SNList_new_count=${SNList_new_count} IPList_count=${IPList_count} SNList_count=${SNList_count} SNList_total_xiangshan_count=${SNList_total_xiangshan_count}" let up_IPList_count=$IPList_count-1 [ $up_IPList_count -eq 0 ] && echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "up_IPList_count is zero, will exit." && exit 0 if [ $up_IPList_count -eq $SNList_new_count ] then echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "process SNList_new success, up_IPList_count == SNList_new_count" echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "Please continue running OTA ......" else echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "process SNList_new failed, up_IPList_count != SNList_new_count" echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "Please check SNList_new file ......" fi exit 0
#!/bin/bash #filename: backup_xiangshan.sh #usage: ./backup_xiangshan.sh sed -i '/^[[:space:]]*$/d' SNList.csv sed -i '/^DeviceSN$/d' SNList.csv rm -f "tmpval" grep -Fxf SNList.csv SNList_total_xiangshan.csv 1>tmpval 2>/dev/null tmpval_count=$(awk 'END {print NR}' tmpval) if [ $tmpval_count -eq 0 ] then echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "need backup xiangshan, will be start backup xiangshan ....." | tee -a backup_xiangshan.log SNList_total_xiangshan_count=$(awk 'END {print NR}' SNList_total_xiangshan.csv) let old_SNList_total_xiangshan_count=$SNList_total_xiangshan_count-1 cat SNList.csv >>SNList_total_xiangshan.csv sed -i '/^[[:space:]]*$/d' SNList.csv echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "add SNList.csv to SNList_total_xiangshan.csv" | tee -a backup_xiangshan.log cur_date="$(date +%Y%m%d%H%M)" cp SNList_total_xiangshan.csv SNList_total_xiangshan_${cur_date}.csv echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "backup SNList_total_xiangshan_${cur_date}.csv" | tee -a backup_xiangshan.log SNList_count=$(awk 'END {print NR}' SNList.csv) let up_SNList_count=$SNList_count up_SNList_total_xiangshan_count=$(awk 'END {print NR}' SNList_total_xiangshan.csv) let last_SNList_total_xiangshan_count=$up_SNList_total_xiangshan_count-1 echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "Old SNList_total_xiangshan count = ${old_SNList_total_xiangshan_count}" | tee -a backup_xiangshan.log echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "update SNList count = ${up_SNList_count}" | tee -a backup_xiangshan.log echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "last SNList_total_xiangshan count = ${last_SNList_total_xiangshan_count}" | tee -a backup_xiangshan.log echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "add update success, backup xiangshan done." | tee -a backup_xiangshan.log else echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "already backup xiangshan, will be stop backup xiangshan ....." | tee -a backup_xiangshan.log SNList_count=$(awk 'END {print NR}' SNList.csv) let up_SNList_count=$SNList_count up_SNList_total_xiangshan_count=$(awk 'END {print NR}' SNList_total_xiangshan.csv) let last_SNList_total_xiangshan_count=$up_SNList_total_xiangshan_count-1 cur_date="$(date +%Y%m%d%H%M)" cp SNList_total_xiangshan.csv SNList_total_xiangshan_${cur_date}.csv echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "backup SNList_total_xiangshan_${cur_date}.csv" | tee -a backup_xiangshan.log echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "old SNList_total_xiangshan count = last SNList_total_xiangshan count" | tee -a backup_xiangshan.log echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "update SNList count = ${up_SNList_count}" | tee -a backup_xiangshan.log echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "last SNList_total_xiangshan count = ${last_SNList_total_xiangshan_count}" | tee -a backup_xiangshan.log echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "skip update success, backup xiangshan done." | tee -a backup_xiangshan.log fi exit 0
#!/bin/bash #filename: checksd.sh #usage: ./checksd.sh ./IPList.csv if [ $# -ne 1 ]; then echo "exit ..." exit 0 fi ip_file=$1 cur_date="$( date '+%Y-%m-%d' )" log_file="checksd_${cur_date}.log" if [ -e $file ]; then echo "TimeDate, DeviceSN, RemoteEndPoint, message" | tee -a $log_file while IFS=, read -r DeviceSN RemoteEndPoint do [ "$DeviceSN" == "DeviceSN" ] && echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "skip DeviceSN first line" && continue echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "DeviceSN: ${DeviceSN}, RemoteEndPoint: ${RemoteEndPoint}" IPAddr=$( echo $RemoteEndPoint | cut -d : -f 1 ) Message="" echo $IPAddr | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null if [ $? -ne 0 ] then echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "Parse IPAddr NG - DeviceSN: ${DeviceSN}, IPAddr: ${IPAddr}" Message="Parse IPAddr NG" echo "$( date +'%Y/%m/%d %H:%M:%S' ), ${DeviceSN}, ${RemoteEndPoint}, ${Message}" | tee -a $log_file continue else echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "Parse IPAddr OK - DeviceSN: ${DeviceSN}, IPAddr: ${IPAddr}" fi ping -c 1 $IPAddr >/dev/null 2>&1 if [ $? -ne 0 ] then echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "Check IPAddr DOWN - DeviceSN: ${DeviceSN}, IPAddr: ${IPAddr}" Message="Check IPAddr DOWN" echo "$( date +'%Y/%m/%d %H:%M:%S' ), ${DeviceSN}, ${RemoteEndPoint}, ${Message}" | tee -a $log_file else echo "$( date +'%Y/%m/%d %H:%M:%S' ) " "Check IPAddr UP - DeviceSN: ${DeviceSN}, IPAddr: ${IPAddr}" Message="$( sshpass -p rockchip ssh root@${IPAddr} 'df -h | grep sd' )" [ -z "$Message" ] && Message="udisk is bad" echo "$( date +'%Y/%m/%d %H:%M:%S' ), ${DeviceSN}, ${RemoteEndPoint}, ${Message}" | tee -a $log_file fi done<"$ip_file" fi exit 0
=========== End