作用:Linux环境下自动远程scp时需要人为介入输入密码,通过expect自动处理密码交互。
文件名:autoscp.sh
代码:
#!/usr/bin/expect
set timeout 300
set username [lindex $argv 0]
set password [lindex $argv 1]
set remhost [lindex $argv 2]
set localfile [lindex $argv 3]
set remotedir [lindex $argv 4]
spawn scp $localfile $username@$remhost:$remotedir
expect {
"*re you sure you want to continue connecting*"
{
send "yes\n"
expect {
"*assword*"
{
send "$password\n"
}
}
}
"*assword*"
{
send "$password\n"
}
}
expect eof
【广告时间:阿里云小站官方上云,近期优惠就用阿里云ECS云服务器。】 © 版权声明
文章版权归作者所有,转载请注明出自Kyrin韩的博客。
THE END
暂无评论内容