Expect Command Automate SSH Login | Tech Arkit


Expect is  a program that "talks" to other interactive programs according to a script.  Following the script, Expect knows what can be expected from a program and what the correct response should be.  An interpreted language provides  branching  and  high-level  control structures to direct the dialogue.  In addition, the user can take control and interact directly when desired, afterward returning control to the script.
Expect scripting language is used to feed input automatically to an interactive program.1
  • Cause your computer to dial you back, so that you can login without paying for the call.
  • Start a game (e.g., rogue) and if the optimal configuration doesn't appear, restart it (again and again) until it does, then hand over control to you.
  • Run fsck, and in response to its questions, answer "yes", "no" or give control back to you, based on predetermined criteria.
  • Connect to another network or BBS (e.g., MCI Mail, CompuServe) and automatically retrieve your mail so that it appears as if it was originally sent to your local system.
  • Carry environment variables, current directory, or any kind of information across rlogin, telnet, tip, su, chgrp, etc.

  1. Send – to send the strings to the process
  2. Expect – Wait for the specific string from the process
  3. Spawn – to start the command
  4. Interact – The interact command allows you to interact with your program. This means that the interact command it says to expect command to release the terminal so you can write things and do things.
  5. Puts – echo out the text