【问题标题】:Expect: answering one or two ssh password prompts then interact期望:回答一两个 ssh 密码提示然后进行交互
【发布时间】:2017-06-08 18:22:01
【问题描述】:

我有一个 ssh 案例(不能使用 sshkeys),有时会提示输入一个密码,有时会提示两个(两种情况下的提示相同)。我尝试了 while、if、exp_continue 的变体,但似乎无法正确烹饪。

如果我只得到一个提示,这很完美:

#!/usr/bin/expect
set pwd "mypwd"
set prompt "*Password*"
set uid "*userid*"
set timeout -1
spawn -noecho ssh -q host.domain

expect $prompt
send $pwd
send \r
interact

试过这个,但没有给我有时需要两个密码加上 KnownHost 案例的结果。

expect {
    "*yes/no*" { send \"yes\r\"; exp_continue }
    $prompt { send \"$pwd\r\"; exp_continue }
    $uid {interact}
}

【问题讨论】:

    标签: ssh passwords expect


    【解决方案1】:

    想通了:

    #!/usr/bin/expect -f
    
    set pwd "mypwd"
    set prompt "Enter PIN for 'PIV_II (PIV Card Holder pin)': "
    set uid "*userid*"
    set timeout -1
    spawn ssh -q host.domain
    
    expect {
        "*yes/no*" { send "yes\r"; exp_continue }
        $prompt { send "$pwd\r"; exp_continue }
        $uid { send \r; interact }
    }
    

    【讨论】:

    • 是的,引用时需要小心一点,但不要小心
    猜你喜欢
    • 2020-02-01
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多