This is a how to successfully combine the shell script dialog tool with expect in order to record all user interactions and repeat them later. You can apply expect to record almost anything on a terminal, I applied it on a very complex dialog-based installation wizard with 100% success. There's nothing special here, nor a magic spell. The solution is pretty straightforward: start recording, launch dialogs + interact, stop record and finally replay it on a hit.
Show the example dialogs below:
I use CentOS 6 for this demo, but it seems to work on other distros:
Assign execution permissions to dlgs.sh:
Start recording using autoexpect:
Call dlgs.sh and interact:
Very simple isn't? See more.
Show the example dialogs below:
#!/bin/bash
#
# dlgs.sh : all dialogs in one script, 1- a radio list, 2- a Yes/No dialog, 3-An input box
radiolist_result=$(dialog --stdout --clear --backtitle "Combining dialog w/ expect" \
--radiolist "Select distro:" 10 40 3 1 "CentOS" off 2 "Ubuntu" on 3 "Debian" off)
dialog --stdout --clear --title "Simple question" --backtitle "Combining dialog w/ expect" \
--yesno "Are you having fun?" 6 25 && yesno_result=Yes || yesno_result=No
inputbox_result=$(dialog --stdout --clear --backtitle "Combining dialog w/ expect" \
--inputbox "Enter your name:" 8 40)
I use CentOS 6 for this demo, but it seems to work on other distros:
$ yum -y install expect
Assign execution permissions to dlgs.sh:
$ chmod +x dlgs.sh
Start recording using autoexpect:
$ autoexpect
autoexpect started, file is script.exp
Call dlgs.sh and interact:
$ ./dlgs.shBy pressing Ctrl+D end the session watch. Then verify the recording by calling the generated script:
...
3
No
Eduardo Lago Aguilar
$ ./script.exp
...
3
No
Eduardo Lago Aguilar
Very simple isn't? See more.