配送後の凍結予想

配送後の凍結予想

次のスクリプトを使用して Alpine Linux のインストールを自動化します。

expect <<- EOF
    set timeout -1
    spawn setup-disk -e -m sys /dev/sda
    expect {
        {WARNING: Erase the above disk(s) and continue? (y/n) \[n\] } {
            send "y\r"
            exp_continue
        }
        "Enter passphrase for /dev/sda3: " {
            send -- "helloworld\r"
            exp_continue
        }
        "Verify passphrase: " {
            send -- "helloworld\r"
            exp_continue
        }
    }
    expect eof
EOF

問題は、スクリプトが2番目のプロンプトに達するたびにパスワードを送信しますが、これ以上続行できず、次のプロンプトを表示せずに停止することです。

ベストアンサー1

「パスワードの確認」の後に、もはや相互作用がないと仮定し、いくつかの小さな変更を行います。

expect <<- EOF
    set timeout -1
    spawn setup-disk -e -m sys /dev/sda
    expect {
        {WARNING: Erase the above disk(s) and continue? (y/n) \[n\] } {
            send "y\r"
            exp_continue
        }
        "Enter passphrase for /dev/sda3: " {
            send -- "helloworld\r"
            exp_continue
        }
        "Verify passphrase: " {
            send -- "helloworld\r"
            # removing `exp_continue`
            # the `expect` command then ends here
        }
    }
    # not `expect eof`, but
    interact
EOF

これで、生成されたプログラムが何をしているのかを見ることができます。

おすすめ記事