使用expect 实现scp 自动输入密码

#!/usr/bin/expect

set src_path "./opencv.tar.gz"
set dst_path "/home/temp"
set passwd "123456"
spawn scp ${src_path} root@${ip}:${dst_path}
expect {
        "password:"
        {
                        send "$passwd\n"
                        }
        "pass"
        {
                        send "$passwd\n"
                }
        "yes/no"
        {
                        sleep 5
                        send_user "send yes"
                        send "yes\n"
                }
        eof
        {
                        sleep 5
                        send_user "eof\n"
                }
        }
        send "exit\r"
expect eof


版权声明:本文为yufengli_原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。