----安装expect
cd /tmp
wget http://core.tcl.tk/tcl/zip/release/tcl.zip
wget https://jaist.dl.sourceforge.net/project/expect/Expect/5.45.3/expect5.45.3.tar.gz
unzip tcl.zip
cd ./tcl/unix
./configure
make
make install
cd /tmp
tar -xzvf expect5.45.3.tar.gz
cd expect5.45.3
./configure
make
make install
expect -v
ln -s /usr/local/bin/expect /usr/bin/expect
expect例子
#!/usr/bin/expect
set timeout 10
set host "192.168.1.118"
set username "root"
set password "Aa123456"
spawn scp /tmp/expect5.45.3.tar.gz $username@$host:/tmp/
expect {
"(yes/no)?"
{
send "yes
"
expect "*assword:" { send "$password
"}
}
"*assword:"
{
send "$password
"
}
}
expect "100%"
expect eof