10台サーバーhostファイルを修正するスクリプト

スクリプトコード:
#!/bin/bash
echo “enter heno’s password"
read henoPassword
echo “enter root’s password"
read rootPassword

for i in 11 12 13 14 15 16 17 18 19 20 21;
do
ip="192.168.10."$i
comand="ssh -o StrictHostKeyChecking=no heno@$ip"
expect -c "
set timeout 60;
spawn $comand;
expect {
\"startnews24@$ip’s password:\" {send \"$henoPassword\r\"; exp_continue}
\"startnews24\" {send \"su -\r\"; exp_continue}
\"Password:\" {send \"$rootPassword\r\"; exp_continue}
\"root@\" {send \"sed -i 's/192.168.* analysis.xxxx.com/192.168.10.221 analysis.xxxx.com/g’ /etc/hosts\rexit\rexit\r\"; exp_continue}
}
"
done

shellscript

Posted by arkgame