Linux自动远程复制脚本,解决脚本密码交互问题

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

    暂无评论内容