expect拷贝文件例子

时间:2023-03-09 16:49:16
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
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