Linux环境自动ssh登录脚本

作用: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云服务器。】
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
评论 抢沙发

    暂无评论内容