shell写的迁移用户脚本-SHELL

 没有多并发& 处理,文件要切成多份多个进程才能并发处理。不可终断,否则要从头读起。
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)

 

转载于:https://www.cnblogs.com/xiaocry/articles/5513437.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值