Tag:ar os sp for on file bs ad as
#!/bin/bashecho "Enter heno ' S password" read henopasswordecho "Enter root" s Password "read rootpasswordfor i in 11 12 13 14 15 16 17 18 19 20 21; do ip= "192.168.10." $i comand= "ssh -o stricthostkeychecking=no [email protected] $ip " expect -c " set timeout 60; spawn $comand; expect { \ "[email protected] $ip ' s password:\ ' {send \ "$henoPassword \r\"; exp_continue} \ "Terry\" {send \ "Su -\r\"; exp_continue} \ "Password:\" {send \ "$ Rootpassword\r\ "; exp_continue} \ "[email Protected]\ " {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
Script logic:
1. Read the user name password from the command line
Log on to server, cut to root--"modify file--Exit root--exit the server---loop
Attention:
If the machine does not have except installed, you need to install expect
CentOS can be installed simply by installing Yum install expect*
A script to modify the requirements of 10 machine host files