#!/usr/bin/expect
set timeout 10
set username [lindex $argv 0]
set host [lindex $argv 1]
#{}包起来密码,因为密码中有个“[”会报错,或者使用\转义 解决方法:http://www.itkeyword.com/doc/8240821665859082x125/expect-script-error-missing-close-brackets
set password {[nk3d*****sgj9}
set src_file [lindex $argv 2]
set dest_file [lindex $argv 3]
spawn scp $username@$host:$src_file $dest_file
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "100%"
expect eof
执行
./sa.exp root host /root/*.tar.gz /root/
针对missing close-bracket的解决办法:
原文:https://www.cnblogs.com/mosicol/p/12858762.html