yum install -y tcl tclx tcl-develvim
wget http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz/downloadssh
tar xzvf downloadspa
cd expect5.45.net
./configureip
make && make installget
ln -sf /data/expect5.45/libexpect5.45.so /usr/lib64/libexpect5.45.soclass
expectfile
vim autossh.shrsa
#!/usr/bin/expectim
set timeout 10
set username [lindex $argv 0]
set password [lindex $argv 1]
set hostname [lindex $argv 2]
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $username@$hostname
expect {
"*assword" {send "$password\r";}
"yes/no" {send "yes\r";exp_continue}
}
expect eof
chmod +x autossh.sh
./autossh.sh root password ip