expect拷贝文件例子

----安装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\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "100%"
expect eof

 

posted @ 2019-01-16 08:55  slnngk  阅读(530)  评论(0编辑  收藏  举报