Search code examples
bashdialogexpect

I need a way to automate an existing script which contains DIALOG


I have an existing BASH script which needs user input. To automate other things, I already have a bash script that contains lots of other code. So the solution should be implementable in bash.

I have already automated parts of the original script which also contain DIALOG boxes. This is solved with EXPECT so far. These DIALOGs however don't contain any selection, only marking and confirming.

I have now gotten stuck because I need to select an option in the DIALOG box with SPACEBAR. I can't continue the original script without the option selected.

So my guess is to either send the space to the DIALOG box or find another key that works to select the option other than SPACEBAR.

This is the relevant part of the code I have:

#!/bin/bash
/usr/bin/expect << 'HEREDOC'
spawn /opt/eri_sn/sbin/foo.bar
sleep 1
send -- {r r}
send -- \r
expect eof
HEREDOC

With this current code the Option is not selected, only confirmed with the RETURN and thus the original script fails. Manually, the option does get selected by pressing SPACEBAR.

I also tried sending the SPACEBAR via Hex Code (send -- r\x20r\r). Trying to only send the SPACEBAR resulted in nothing sent in a test script, so send -- {r r} is a solution for this. Also, I tried to get the needed lines via autoexpect. This however also only shows:

send -- " "
send -- "\r"

Also, there isn't a way to call the original script in a way that would make this work.

I know I could copy all relevant parts out of the original script, but it's from the manufacturer and might change with different versions.

Thanks in advance


Solution

  • I was creating a minimal reproducible example, like pynexj said, when I realized that I just had another line of send -- \r in my code. Because of this, everything I tried didn't matter, and I was just wasting my time. The question might as well be deleted, sorry.