没有多并发& 处理,文件要切成多份多个进程才能并发处理。不可终断,否则要从头读起。
cat move_orgid_logout_wxl.sh
#!/bin/bash
# Move user Command, eg:
#/home/richmail/bin/NNDD --move-user-to-miid 账号 'miNodeId=113&miNodeVolId=1&orgid=1'
FILE_NAME="$1"
TO_MI="$2"
#TO_NODE="$3"
VolId_num="$3"
TO_ORG="$4"
current_dir="${PWD}"
LOG_PATH="${current_dir}/logs"
echo $LOG_PATH
/usr/bin/id | /bin/grep -qi 'root'
if [ $? -ne 0 ]; then
echo "User error: $USER is not root!"
exit
fi
if [ $# -ne 4 ]; then
cat ${current_dir}/readme.txt
exit
fi
if [ -e "${current_dir}/rm.txt" ]; then
mv ${current_dir}/rm.txt ${current_dir}/rm.txt.`date +%m%d%H%M%S`
fi
if [ -e "${current_dir}/no_e.txt" ]; then
mv ${current_dir}/no_e.txt ${current_dir}/no_e.txt.`date +%m%d%H%M%S`
fi
if [ $# -ne 4 ]; then
echo "Please Input Right args"
exit
fi
if [ ! -e $FILE_NAME ]; then
echo File: $FILE_NAME, Not found!
exit
fi
if [[ ! "$TO_MI" =~ "[0-9]" ]]; then
echo $TO_ORG not a digit
exit
fi
if [[ ! "$VolId_num" =~ "[0-9]" ]]; then
echo $VolId_num Not a digit
exit
fi
if [[ ! "$TO_ORG" =~ "[0-9]" ]]; then
echo $TO_ORG Not a digit
exit
fi
if [ ! -d $LOG_PATH ]; then
mkdir -p $LOG_PATH
fi
#循环前标记
echo "$(date +"%F %T") start -------------" >> ${LOG_PATH}/success.log.$(date +%F)
echo "$(date +"%F %T") start -------------" >> ${LOG_PATH}/success.log.num.$(date +%F)
echo "$(date +"%F %T") start -------------" >> ${LOG_PATH}/online.log.$(date +%F)
echo "$(date +"%F %T") start -------------" >> ${LOG_PATH}/online.log.num.$(date +%F)
echo "$(date +"%F %T") start -------------" >> ${LOG_PATH}/MoveMiFile.log.$(date +%F)
echo "$(date +"%F %T") start -------------" >> ${LOG_PATH}/MoveMiFile.log.num.$(date +%F)
echo "$(date +"%F %T") start -------------" >> ${LOG_PATH}/unnormal.log.$(date +%F)
echo "$(date +"%F %T") start -------------" >> ${LOG_PATH}/unnormal.log.num.$(date +%F)
#是否为RM账号
while read num
do
/home/richmail/bin/userutil --mdinfo $num |awk -v D=${num} 'END{if(NR>10){print D >>"rm.txt"} else{print D >>"no_e.txt"}}'
done <${FILE_NAME}
if [ ! -e "${current_dir}/rm.txt" ];then
echo "No exits RM number"
exit
fi
TO_NODE=1;
#账号分类统计记录
while read line
do
if [ ${TO_NODE} -gt $VolId_num ];then
echo "error"
exit
elif [ ${TO_NODE} -eq $VolId_num ];then
/home/richmail/bin/logoutbyname $line
/home/richmail/bin/userutil --move-user-to-miid $line "miNodeId=${TO_MI}&miNodeVolId=${TO_NODE}&orgid=${TO_ORG}"| \
awk -v P=${LOG_PATH} -v D=$(date +%F) -v L=${line} 'NR==1{
if (/step=CheckOnline/) {
printf "%s,%s, user_online:%s\n", strftime("%F %T", systime()),systime(),$0 >> P"/online.log."D
printf "%s\n", L>> P"/online.log.num."D
}
else if (/success\.$/) {
printf "%s,%s,%s\n", strftime("%F %T", systime()),systime(),$0 >> P"/success.log."D
printf "%s\n", L>> P"/success.log.num."D
}
else if (/step=MoveMiFile/) {
printf "%s,%s,%s\n", strftime("%F %T", systime()),systime(),$0 >> P"/MoveMiFile.log."D
printf "%s\n", L>> P"/MoveMiFile.log.num."D
}
else {
printf "%s,%s,%s unknown_error:%s\n",strftime("%F %T", systime()),systime(),L,$0 >> P"/unnormal.log."D
printf "%s\n",L >> P"/unnormal.log.num."D
}
}'
echo "this is ${TO_NODE} "
TO_NODE=1
else
/home/richmail/bin/logoutbyname $line
/home/richmail/bin/userutil --move-user-to-miid $line "miNodeId=${TO_MI}&miNodeVolId=${TO_NODE}&orgid=${TO_ORG}"| \
awk -v P=${LOG_PATH} -v D=$(date +%F) -v L=${line} 'NR==1{
if (/step=CheckOnline/) {
printf "%s,%s, user_online:%s\n", strftime("%F %T", systime()),systime(),$0 >> P"/online.log."D
printf "%s\n", L>> P"/online.log.num."D
}
else if (/success\.$/) {
printf "%s,%s,%s\n", strftime("%F %T", systime()),systime(),$0 >> P"/success.log."D
printf "%s\n", L>> P"/success.log.num."D
}
else if (/step=MoveMiFile/) {
printf "%s,%s,%s\n", strftime("%F %T", systime()),systime(),$0 >> P"/MoveMiFile.log."D
printf "%s\n", L>> P"/MoveMiFile.log.num."D
}
else {
printf "%s,%s,%s unknown_error:%s\n",strftime("%F %T", systime()),systime(),L,$0 >> P"/unnormal.log."D
printf "%s\n",L >> P"/unnormal.log.num."D
}
}'
echo "this is ${TO_NODE} less than 8"
((TO_NODE++))
fi
done < ${current_dir}/rm.txt
#循环后标记
echo "$(date +"%F %T") stop -------------" >> ${LOG_PATH}/success.log.$(date +%F)
echo "$(date +"%F %T") stop -------------" >> ${LOG_PATH}/success.log.num.$(date +%F)
echo "$(date +"%F %T") stop -------------" >> ${LOG_PATH}/online.log.$(date +%F)
echo "$(date +"%F %T") stop -------------" >> ${LOG_PATH}/online.log.num.$(date +%F)
echo "$(date +"%F %T") stop -------------" >> ${LOG_PATH}/MoveMiFile.log.$(date +%F)
echo "$(date +"%F %T") stop -------------" >> ${LOG_PATH}/MoveMiFile.log.num.$(date +%F)
echo "$(date +"%F %T") stop -------------" >> ${LOG_PATH}/unnormal.log.$(date +%F)
echo "$(date +"%F %T") stop -------------" >> ${LOG_PATH}/unnormal.log.num.$(date +%F)