dr-mysql01:/root# Cat a1.sh# User name uname= "$" #密码passwd = "$" #执行检测并安装expect模块ep = ' Rpm-qa | grep expect ' if [-Z $ep ]; then echo "Detects your system, does not have expect module installed, ready to perform installation" Sleep 2 yum install-y expectelse echo "has been installed ExPEC T module, after 3 seconds, begins to perform SSH file synchronization "Sleep 3fi# public key no SSH authentication Module CAT Hosts | While read Hostdoecho "currently transferring SSH files to $host" expect <<eofspawn scp-r. ssh/ $host:/$uname Expect {"*yes/no" {send "yes\r"; exp_continue} "*password:" {send "$passwd \ r"; Exp_continue }}eofecho "currently on $host for public key authentication ..." Sleep 2expect <<eofspawn Ssh-copy-id -I. ssh/id_rsa.pub $host expect {"*yes/no" {send "yes\r"; exp_continue} "* Password: "{send" $passwd \ r "; exp_continue }}eofecho" Certification successful ... "done# switch root permissions for Hosts file distribution echo" Sync native Hosts file to each machine "Sleep # Synchronizes native hosts files to various other machines
2nd time increase the SSH host Trust script