预计发送后会冻结

预计发送后会冻结

我正在尝试使用以下脚本自动化 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

问题是,每当脚本到达第二个提示时,它都会发送密码,但无法进一步继续,它只是挂起而不显示下一个提示

答案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

现在,您应该能够看到生成的程序正在做什么。

相关内容