作用:Linux环境下需要通过ssh登录做一些自动化处理,通过expect解决人工介入输入密码的交互问题。
文件名:autossh.sh
代码:
#!/usr/bin/expect
set timeout 300
set username [lindex $argv 0]
set password [lindex $argv 1]
set remhost [lindex $argv 2]
set command [lindex $argv 3]
spawn ssh $username@$remhost $command
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
暂无评论内容