0

How can I do the same thing as done here using ansible expect to create nessus user (nessuscli) without using Ansible ? I am trying following with no luck:

#!/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
Shubham Vaishnav
  • 1,637
  • 6
  • 18
Sans
  • 1
  • 1
  • 2
    Hello, what is the error you getting ? can you share the error ? Also, can you add the execution result ? – P.... Feb 10 '21 at 19:18

1 Answers1

0

The code in the answer you linked to does not contain \r sequences inside the expect match expressions, nor does a more traditional example

Thus, I suspect you will get a lot further by removing the \r sequences from the expect blocks:

#!/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
mdaniel
  • 31,240
  • 5
  • 55
  • 58