Expect - PowerPoint PPT Presentation

About This Presentation
Title:

Expect

Description:

Useable in interactive applications such as telnet, ftp, passwd, fsck, rlogin, ... IBM, HP, Sun, Xerox, Amdahl, Tektronix, AT&T, ComputerVision and the World Bank ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 12
Provided by: mik9175
Learn more at: https://grothoff.org
Category:
Tags: expect | tektronix

less

Transcript and Presenter's Notes

Title: Expect


1
Expect
  • Tool for Automation and Testing

2
Expect - Introduction
  • Unix automation and testing tool
  • Written by Don Libes
  • Primarily designed as an extension to the Tcl
    scripting language
  • Useable in interactive applications such as
    telnet, ftp, passwd, fsck, rlogin, tip, ssh, and
    others.

3
Expect TCL Basics
  • Everything is a command
  • No Fixed Parser
  • Case-Sensitive
  • Explicit Expression Evaluation
  • set a 5 ? a 5
  • set b a2 ? b a2
  • set c expr a2 ? c 7 (Note for variable
    substitution)
  • Simple variables are strings of arbitrary length
  • Real Int ? cast to real
  • Non-numeric string and real/int ? cast to string
  • Built in Lists
  • Standard flow control structures (while, if,
    etc.)
  • String manipulation with Regular Expressions
  • Procedures arguments can be passed by value or
    reference
  • Tool Command Language

4
Expect The Programming Language
  • Extension of TCL, so the syntax is TCL syntax
  • Basic command set
  • expect
  • send
  • spawn
  • Interact
  • Regular Expression pattern
  • matching
  • Glue to combine separate
  • executables

5
Expect Pros / Cons
  • Pros
  • Built on existing system tools, so learning curve
    is small.
  • Extensive support from corporate entities
    Silicon Graphics, IBM, HP, Sun, Xerox, Amdahl,
    Tektronix, ATT, ComputerVision and the World
    Bank
  • Numerous ports to other programming languages
    (Perl, Python, java, etc.)
  • Cons
  • Only useful for command line scripting
  • Cryptic syntax for those unfamiliar with TCL
    (When do I use a again?)
  • Generally machine dependent tools are run with
    Expect, so porting scripts cross-platform is not
    easily supported.

6
Expect Hello World!
  • Start Expect with expect or write the script to
    a file and run gt expect filename
  • send Hello World!\n
  • expect Hi\n
  • Putting it together
  • Expect Hi\n
  • send Hi World!\n

7
Expect More Advanced
  • expect "hi\n" send "Hi World!\n" \
  • "hello\n" send "Hello World!\n"
    \
  • "bye\n" send "Bye World!\n"

8
Expect - Automation
  • spawn ftp argv
  • expect "Name" send "anonymous\r" \
  • "name" send "anonymous\r"
  • expect "assword"
  • send "nobody_at_nobody.com\r"
  • interact

9
Expect - Others
  • Brute Force security
  • Beer
  • Chess
  • Weather
  • Rogue
  • Hunt

10
Expect - GnuChess
  • start things rolling
  • spawn gnuchess
  • set id1 spawn_id
  • expect "White \\(1\\) "
  • send "random\r"
  • send "depth 6\r"
  • send "go\r"
  • read_first_move
  • expect -re "My move is (.)\n"
  • spawn gnuchess
  • set id2 spawn_id
  • expect "White \\(1\\) "
  • send "random\r"
  • send "depth 5\r"
  • send expect_out(1,string)
  • while 1
  • expect
  • -i id2 -re "is (.)\n"
  • send -i id1 expect_out(1,string)
  • -i id1 -re "is (.)\n"
  • send -i id2 expect_out(1,string)

11
Expect - Questions
Write a Comment
User Comments (0)
About PowerShow.com