Expect
Cet article est une ébauche concernant l’informatique.
Expect
| Développé par | Don Libes |
|---|---|
| Dernière version | 5.45.4 ()[1],[2] |
| Écrit en | Expect, Tcl |
| Système d'exploitation | POSIX et Microsoft Windows |
| Environnement | GNU/Linux, FreeBSD, NetBSD, OpenBSD, MS Windows |
| Type |
Langage en ligne de commande (d) Langage de programmation Auto clicker (en) |
| Licence | Domaine public[3] |
| Site web | core.tcl.tk/expect/index |
Expect est un outil 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.
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-dessous, 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
- ↑ « Expect: Expect » (consulté le )
- ↑ « Expect - Browse /Expect/5.45.4 at SourceForge.net », (consulté le )
- ↑ (en) Financement américain - National Institute of Standards and Technology.
- (en) Cet article est partiellement ou en totalité issu de l’article de Wikipédia en anglais intitulé « Expect » (voir la liste des auteurs).
Voir aussi
Articles connexes
Liens externes
- (en) Code source Expect la plate-forme d'hébergement SourceForge.net.
- (en) Page web SourceForge.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.