#!/usr/bin/expect
#全自助版
#modify_centerip.sh
#newgk_ip.txt格式(以空格隔开): ip user password
#前提条件
#rpm -qa |grep expect
#rpm -qa |grep sshd
#yum install expect
set timeout 3
while read line
do
IP=`echo $line | awk '{print $1}'`
user=`echo $line | awk '{print $2}'||echo 'gsmc'`
pwd1=`echo $line | awk '{print $3}'||echo 'gsmc'`
echo -e "\n\033[47;30m================== start : $user@$IP $pwd1 =========================\033[0m"
#自动执行
expect <<- EOF
spawn ssh $user@$IP
expect {
"*(yes/no)?*" {
send "yes\r"
expect "password"
send "$pwd1\r"
}
"password" {
send "$pwd1\r"
}
}
expect "*]*"
send "sed -i 's/CenterIP/10.188.1.148/g' /home/gsmc/smkenter/conf/webservice.properties\r"
expect "*]*"
send "grep '10.188.1.148' /home/gsmc/smkenter/conf/webservice.properties\r";
expect "*]*"
send "grep 'CenterIP' /home/gsmc/smkenter/conf/webservice.properties\r"
expect "*]*"
send "exit\r"
EOF
echo $IP>>./pass.txt
echo -e "\n\033[40;37m=========================== complete : $IP ===================================\033[0m\n\n"
# sleep 0.5
done < newgk_ip.txt
#!/bin/bash
#手动输密码版
#modify_centerip.sh
while read line
do
IP=`echo $line | awk '{print $1}'`
rootm=`echo $line | awk '{print $2}'`
echo -e "\033[41;5m=======开始执行IP:$line ==========================\033[0m"
ssh -l gsmc $IP "sed -i 's/CenterIP/10.188.1.148/g' /home/gsmc/smkenter/conf/webservice.properties;grep -E '10.188.1.148' /home/gsmc/smkenter/conf/webservice.properties"
echo -e "\033[41;5m=======开始执行IP:$line ==========================\033[0m"
done < newgk_ip.txt
升级后:
#!/bin/bash
while read line
do
echo "开始执行IP:$line =================="
ssh -l gsmc $line "sed -i 's/^M//g' /home/gsmc/smkenter/conf/webservice.properties"
echo "完成执行对IP:$line 操作=============="
done < file("newgk_ip.txt")
sh modify_centerip1.sh |tee >>logs.log
wc -l pass.txtr ;tail -F pass.txtr |nl
wc -l logs.log ;tail -F logs.log |nl