autoexpect, one of the example programs written in and distributed with Expect, monitors an interactive shell session and generates an analagous Expect script.
autoexpect is an application to create an application! Once you start autoexpect, you then perform the actions that you want to script with Expect. Once you complete, it is well worth while to exercise the script to see that it does all that you really want it to do and that all error cases are handled.
A script generated by autoexpect can be less readable and more difficult to modify than a script written by a human.
When designing Expect scripts, it can be useful to look at autoexpect-generated scripts for inspiration and hints.