expect

A Unix tool written in Tcl and a script language for automating the operation of interactive applications such as telnet, FTP, passwd, fsck, rlogin, tip, etc.. Expect can feed input to other programs and perform pattern matching on their output. It is also useful for testing these applications. By adding Tk, you can also wrap interactive applications in X11 GUIs.

http://expect.nist.gov/.

["expect: Scripts for Controlling Interactive Tasks", Don Libes, Comp Sys 4(2), U Cal Press Journals, Nov 1991].