#使用scp传输文件(从服务器A传文件到服务器B)
#!/usr/bin/expect
set timeout -1
spawn scp A_path B_username@B_IP:B_path
expect {
"password" {send "$B_password
";}
"yes/no" {send "yes
";exp_continue}
}
expect eof
exit
#使用scp传输文件(从服务器B下载文件到服务器A)
#!/usr/bin/expect
set timeout -1
spawn scp B_username@B_IP:B_path A_path
expect {
"password" {send "$B_password
";}
"yes/no" {send "yes
";exp_continue}
}
expect eof
exit
##假如输出包含yes/no,则表示是第一次登入,需要输入yes来添加信任。exp_continue表示继续此循环