Expect

Expect
Expect
Importez le logo de ce logiciel
Développeur Don Libes
Dernière version 5.44.1.15 (11 mars 2011) [+/−]
Écrit en Expect, Tcl
Environnement GNU/Linux, FreeBSD, NetBSD, OpenBSD, MS Windows
Licence Domaine public[1]
Site web http://expect.nist.gov/

Expect est un outils d'automation et de tests de non-régression écrit par Don Libes comme extension au langage de script Tcl pour tester des applications interactives comme telnet, ftp, passwd, fsck, rlogin, ssh, ou bien d'autres.

Sommaire

Exemples

Un exemple simple de script automatisant une session telnet:

  # 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_id\r" expect "password:"
# Send the password, and then wait for a shell prompt. send "$my_password\r" expect "%"
# Send the prebuilt command, and then wait for another shell prompt. send "$my_command\r" 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 "exit\r" expect eof

Un autre exemple de script testant 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_id\r" expect "password:"
# Send the password, and then wait for an ftp prompt. send "$my_password\r" expect "ftp>"
# Switch to binary mode, and then wait for an ftp prompt. send "bin\r" expect "ftp>"
# Turn off prompting. send "prompt\r" 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 "bye\r" expect eof

Et enfin ci-dessou, un exemple de test sftp, avec mot de passe:

 #!/usr/local/bin/expect -f #<---insert here your expect program location
 
 # procedure to attempt connecting; result 0 if OK, 1 otherwise
 proc connect {passw} {
  expect {
    "Password:" { 
        send "$passw\r"
        expect {
           "sftp*" {
                return 0
            }  
        }
     }
  }
  # timed out
  return 1
 }
 
 #read the input parameters
 set user [lindex $argv 0]
 set passw [lindex $argv 1]
 set host [lindex $argv 2]
 set location [lindex $argv 3]
 set file1 [lindex $argv 4]
 set file2 [lindex $argv 5]
 
 #puts "Argument data:\n";
 #puts "user: $user";
 #puts "passw: $passw";
 #puts "host: $host";
 #puts "location: $location";
 #puts "file1: $file1";
 #puts "file2: $file2";
 
 #check if all were provided
 if { $user == "" || $passw == "" || $host == "" || $location == "" || $file1 == "" || $file2 == "" }  {
   puts "Usage: <user> <passw> <host> <location> <file1 to send> <file2 to send>\n"
   exit 1
 }
 
 #sftp to specified host and send the files
 spawn sftp $user@$host
 
 set rez [connect $passw]
 if { $rez == 0 } {
   send "cd $location\r"
   set timeout -1
   send "put $file2\r"
   send "put $file1\r"
   send "ls -l\r"
   send "quit\r"
   expect eof
   exit 0
 }
 puts "\nError connecting to server: $host, user: $user and password: $passw!\n"
 exit 1

Notes et références

Voir aussi

Articles connexes

Liens externes



Wikimedia Foundation. 2010.

Contenu soumis à la licence CC-BY-SA. Source : Article Expect de Wikipédia en français (auteurs)

Игры ⚽ Поможем написать реферат

Regardez d'autres dictionnaires:

  • Expect — Тип инструмент для автоматизации и тестирования интерактивных приложений Разработчик Don Libes Написана на Tcl Операционная система Кроссплатформенное программное обеспечение Последняя версия 5.44.1 (31 января 2006 года) …   Википедия

  • Expect — Ex*pect , v. t. [imp. & p. p. {Expected}; p. pr. & vb. n. {Expecting}.] [L. expectatum, to look out for, await, expect; ex + out spectare to look at. See {Spectacle}.] 1. To wait for; to await. [Obs.] [1913 Webster] Let s in, and there expect… …   The Collaborative International Dictionary of English

  • expect — expect, hope, look, await are comparable when they mean to have something in mind as more or less certain to happen or come about. They vary, however, so greatly in their implications and in their constructions that they are seldom… …   New Dictionary of Synonyms

  • expect — [ek spekt′, ikspekt′] vt. [L expectare, exspectare < ex , out + spectare, to look, freq. of specere, to see: see SPECTACLE] 1. to look for as likely to occur or appear; look forward to; anticipate [I expected you sooner] 2. to look for as due …   English World dictionary

  • expect — was the object of much criticism during the 19c when it was used to mean ‘to suppose, surmise’, as in I expect you d like a drink. Fowler, however, regarded it as a natural extension of meaning and wrote (1926) that ‘it seems needless purism to… …   Modern English usage

  • expect — [v1] believe strongly; anticipate apprehend, assume, await, bargain for, bargain on, be afraid, calculate, conjecture, contemplate, count on, divine, envisage, feel, figure, forecast, foreknow, foresee, gather, hope, hope for, imagine, in the… …   New thesaurus

  • Expect — Ex*pect , v. t. To wait; to stay. [Obs.] Sandys. [1913 Webster] …   The Collaborative International Dictionary of English

  • Expect — Ex*pect , n. Expectation. [Obs.] Shak. [1913 Webster] …   The Collaborative International Dictionary of English

  • expect — I (anticipate) verb await, bargain for, be certain, be confident, be prepared, calculate upon, count on, expectare, have in prospect, look for, look forward to, plan on, prepare for, provide for, reckon on, sperare, wait for, watch for associated …   Law dictionary

  • expect — 1550s, wait, defer action, from L. expectare/exspectare await, look out for, desire, hope, from ex thoroughly (see EX (Cf. ex )) + spectare to look, frequentative of specere to look at (see SCOPE (Cf. scope) (1)). Figurative sense of …   Etymology dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”