Expect! I learned Tcl just for Expect. It’s one of those tools that takes you from “I have no idea how to do this” to “this is trivial” in just an afternoon.
I use the Perl Expect.pm module (https://metacpan.org/pod/release/RGIERSIG/Expect-1.15/Expect...) since I create and maintain a lot of Perl scripts. It combines the utility of expect with the power of Perl regexes.