Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications. And by adding Tk, you can also wrap interactive applications in X11 GUIs. Expect can make easy all sorts of tasks that are prohibitively difficult with anything else. You will find that Expect is an absolutely invaluable tool - using it, you will be able to automate tasks that you’ve never even thought of before - and you’ll be able to do this automation quickly and easily.
From Expect
Some Good References:
- 6 Expect Script Examples to Expect the Unexpected (With Hello World)
- Expect Script Tutorial: Expressions, If Conditions, For Loop, and While Loop Examples
- Using Expect Scripts to Automate Tasks
Another reference is a Simple Introduction, download[pdf]:
Exploring Expect is a Expect book, download[pdf]:
The Man of Expect
is also very good and need to read.
Another references:
Last, a simple example use expect to login by ssh and execute free command to see the memory:
#!/usr/bin/expect
spawn ssh root@x.x.x.x
expect "password: "
send "PASSWORD\r"
expect "# "
send "free -mt\r"
expect "# "
send "exit\r"