Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The venerable "expect"

The venerable "expect"

Expect tool fundamentals. Accompanying code: https://gist.github.com/bruno-/dc4255f6d426af00c240

Bruno Sutic

January 29, 2015
Tweet

More Decks by Bruno Sutic

Other Decks in Programming

Transcript

  1. What is expect? • a classic Unix tool • enables

    automating *everything* in the terminal • written in 1990, Tcl
  2. Can’t script everything • ssh password entry? • sudo password

    entry? • doing multiple ssh “hops”, usually password protected
 (enterprises, telecoms) • interactive command line applications (tmux) • (short demo)
  3. Expect is… • surprisingly easy to learn • powerful •

    easily available (installed by default on OS X) • does not replace scripting, use it for small % of tasks
  4. Commands summary • spawn - starts a program • expect

    - “listens” for output • send - “types” program input • interact - gives control to the user
  5. Commands summary • log_user 0 - make the script quiet

    • puts - print to the screen • set timeout 10
 …
 timeout { exit 1 }
  6. My real-world usage examples • Ericsson NT - automating SSH

    connections (3-4 hops) • Automated testing for tmux plugins • tmux plugin manager • tmux copycat