0

如何在不使用 Ansible 的情况下使用 ansible希望创建 nessus 用户 (nessuscli)来执行与此处相同的操作?我正在尝试没有运气:

#!/usr/bin/expect -f

set timeout -5

spawn /opt/nessus/sbin/nessuscli adduser

expect "(.*)Login(.*):\r"

send -- "admin\r"

expect "(.*)Login password(.*)\r" send -- "password\r"

expect "(.*)Login password(.*)\r" send -- "password\r"

expect "(.*)system administrator(.*)\r" send -- "y\r"

expect "(.*)rules set(.*):\r" send -- "\n\r"

expect "(.*)ok(.*):\r" send -- "y\r"

expect eof
4

1 回答 1

0

您链接到的答案中的代码不包含\r期望匹配表达式中的序列,更传统的示例也不包含

因此,我怀疑通过从块中删除\r序列你会得到更多:expect

#!/usr/bin/expect -f

set timeout -5

spawn /opt/nessus/sbin/nessuscli adduser

expect "(.*)Login(.*):"
send -- "admin\r"

expect "(.*)Login password(.*)"
send -- "password\r"

expect "(.*)Login password(.*)"
send -- "password\r"

expect "(.*)system administrator(.*)"
send -- "y\r"

expect "(.*)rules set(.*):"
send -- "\n\r"

expect "(.*)ok(.*):"
send -- "y\r"

expect eof
于 2021-02-11T05:22:14.310 回答