FACTOID # 62: The four largest nations are Russia, China, USA, and Canada.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Expect

Expect is a Unix automation and testing tool, written by Don Libes, for interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. With Tk, interactive applications can be wrapped in X11 GUIs. Unix (officially trademarked as UNIX) is a computer operating system originally developed in the 1960s and 1970s by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie, and Douglas McIlroy. ... Application software is a defined subclass of computer software that employs the capabilities of a computer directly to a task that the user wishes to perform. ... TELNET is a network protocol used on the Internet or local area network LAN connections. ... The abbreviation FTP can refer to: The File Transfer Protocol used on the Internet. ... passwd is a tool on most Unix and Linux systems used to change a users password. ... The system utility fsck (for file system check or file system consistency check) is a tool for checking the consistency of a file system in the Unix system and clones thereof. ... In computing, rlogin is a Unix software utility that allows users to log in on another host via a network, communicating via TCP port 513. ... now. ... In computing, Secure shell, or SSH, is both a computer program and an associated network protocol designed for logging into and executing commands on a remote computer. ... In computing, Tk is an open source, cross-platform widget toolkit, that is, a library of basic elements for building a graphical user interface (GUI). ... In computing, the X Window System (commonly X11 or X) is a windowing system for bitmap displays. ... GUI can refer to the following: GUI is short for graphical user interface, a term used to describe a type of interface in computing. ...

Contents

Basics

Expect is an extension of Tcl with two significant commands added: send, and expect. These allow a script to control command-line tools originally designed to interact only with a human. For example, programs which interactively prompt for a password cannot be automated with shell scripts or other languages but can be trivially automated with an Expect script. Tcl (originally from Tool Command Language, but nonetheless conventionally rendered as Tcl rather than TCL; and pronounced like tickle) is a scripting language created by John Ousterhout. ...


Expect has regular expression pattern matching and general program capabilities, allowing simple scripts to intelligently control programs such as telnet, ftp, and ssh, all of which lack a programming language, macros, or any other program mechanism. The result is that Expect scripts provide old tools with significantly new power, flexibility, and reliability. In computing, a regular expression (abbreviated as regexp or regex, with plural forms regexps, regexes, or regexen) is a string that describes or matches a set of strings, according to certain syntax rules. ...


Examples

A simple example is a script that automates a telnet session:

 # Assume $remote_server, $my_user_id, $my_password, and $my_command were read in earlier # in the script.
# Open a telnet session to a remote server, and wait for a username prompt. spawn telnet $remote_server expect "username:"
# Send the username, and then wait for a password prompt. send "$my_user_idr" expect "password:"
# Send the password, and then wait for a shell prompt. send "$my_passwordr" expect "%"
# Send the prebuilt command, and then wait for another shell prompt. send "$my_commandr" expect "%"
# Capture the results of the command into a variable. This can be displayed, or written to disk. set results $expect_out(buffer)
# Exit the telnet session, and wait for a special end-of-file character. send "exitr" expect eof

Another example is a script that automates ftp:

 # Open an ftp session to a remote server, and wait for a username prompt. spawn ftp $remote_server expect "username:"
# Send the username, and then wait for a password prompt. send "$my_user_idr" expect "password:"
# Send the password, and then wait for an ftp prompt. send "$my_passwordr" expect "ftp>"
# Switch to binary mode, and then wait for an ftp prompt. send "binr" expect "ftp>"
# Turn off prompting. send "promptr" expect "ftp>"
# Get all the files send "mget *r" expect "ftp>"
# Exit the ftp session, and wait for a special end-of-file character. send "byer" expect eof

Usage

Expect serves as a "glue" to link existing utilities together. The general idea is to try to figure out how to make Expect utilize the system's existing tools rather than figure out how to solve a problem inside of Expect.


A key usage of Expect involves commercial software products. Many of these products provide some type of command-line interface, but these usually lack the power needed to write scripts. They were built to service the users administering the product, but the company often doesn't spend the resources to implement a fully robust scripting language. An Expect script can spawn a shell, look up environmental variables, perform some Unix commands to retrieve more information, and then enter into the product's command-line interface armed with the necessary information to achieve the user's goal. After looking up information inside the product's command-line interface, the script can make an intelligent decision about what action to take, if any. Scripting programming languages (commonly called scripting languages or script languages) are computer programming languages designed for scripting the operation of a computer. ...


Every time an Expect operation is completed, the results are stored in a local variable called $expect_out. This allows the script to both harvest information to feedback to the user, and it also allows conditional behavior of what to send next based on the circumstances.


A common use of Expect is to set up a testing suite, whether it be for programs, utilities or embedded systems. DejaGnu is a testing suite written using Expect for use in testing. It has been used extensively for testing gcc and is very well suited to testing remote targets such as embedded development. DejaGnu is a framework for testing other programs. ... The GNU Compiler Collection (usually shortened to GCC) is a set of programming language compilers produced by the GNU Project. ...


Opinion

Pros

Expect can be run at regular intervals through the use of cron to encapsulate system administration tasks. The reason this works is because Expect merely uses system administration tools already located on the host computer. No extra tools need to be learned. If the programmer has already learned Tcl, then migrating to Expect is a relatively easy transition. The same programming structures and syntax exist, but with additional features built in. Surname redirect crontab ... Tcl (originally from Tool Command Language, but nonetheless conventionally rendered as Tcl rather than TCL; and pronounced like tickle) is a scripting language created by John Ousterhout. ...


There is large support in the industry for using Expect for many in-house administration tasks. It is widely used by companies such as Silicon Graphics, IBM, HP, Sun, Xerox, Amdahl, Tektronix, AT&T, ComputerVision and the World Bank to run in-house automated testing for development projects, file transfers, account administration, and network testing.


Expect has been ported to Python and Perl languages in various add-on module projects. A subset of Expect commands has been ported to java and is embedded within SwitchTermJ (java-based Terminal Emulator) . Subroutines generally are an interpretation of the original version - with equivalent functionality. Once you understand the concepts, you can move to other languages as needed.


Cons

Expect inherits the same syntax convention as Tcl, which may seem unfamiliar if used to other script languages. Compared to languages such as bash, csh, and Perl, Expect has a different twist. It is sometimes challenging to remember when a variable must be prefixed with a "$", and when it must not. There are versions of Expect available for Perl and Python for those familiar with their syntax. bash is a Unix shell written for the GNU Project. ... The C shell (csh) is a Unix shell developed by Bill Joy for the BSD Unix system. ... Perl is a dynamic programming language created by Larry Wall and first released in 1987. ... Perl is a dynamic programming language created by Larry Wall and first released in 1987. ... Python is a programming language created by Guido van Rossum in 1990. ...


Another limitation is the difficulty in porting Expect scripts between platforms. For example, an Expect script that was written to use several Unix-based tools, might not be suitable if migrated to a Windows platform. If possible, the programmer must find counterpart command-line applications that provide the same information, and this will probably require changing the send/expect's, which can be a major part of the script. This is not an issue if you load tcl, perl or python on the machines in question, and use those languages native posix interfaces for accessing files (open/close) and so on, as well as using standard posix utilities (telnet, ftp etc.) for remote interaction.


Also, Expect automates command-line tools, not GUI-based tools. While Windows offers many valuable tools, many are GUI-based and thus outside the reach of Expect. This however is a limitation of Windows, not Expect; and there are several ways to solve this problem. GUI can refer to the following: GUI is short for graphical user interface, a term used to describe a type of interface in computing. ...


References

  • Libes, Don (1995). Exploring Expect: A Tcl-Based Tool for Automating Interactive Programs. O'Reilly & Associates, Inc. ISBN 1-56592-090-2.

External links


  Results from FactBites:
 
Expect (11774 words)
Expect is a program that "talks" to other interactive pro- grams according to a script.
Expectk is a mixture of Expect and Tk.
However, because expect is not line oriented, these characters match the beginning and end of the data (as opposed to lines) currently in the expect matching buffer.
Expect - Wikipedia, the free encyclopedia (1023 words)
Expect is a Unix automation and testing tool, written by Don Libes, for interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others.
Expect has regular expression pattern matching and general program capabilities, allowing simple scripts to intelligently control programs such as telnet, ftp, and ssh, all of which lack a programming language, macros, or any other program mechanism.
Expect can be run at regular intervals through the use of cron to encapsulate system administration tasks.
  More results at FactBites »


 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m