Questions tagged [expect]

Expect is a Unix/Linux extension for the Tcl scripting language. It was designed as an automation and testing tool and it makes it trivial to interact with complex programs, such as remote shells, security maintenance. It has particularly powerful response recognition.

Expect adds many extensions to the Tcl scripting language which simplify scripting interactive applications controlling such hard-to-interact programs such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. Expect/tcl can run a GUI interface or run from the command line. Since Tcl is a full featured programming language, Expect can easily interact with databases, webservers, etc. with intuitive, powerful, and easy-to-anticipate processing.

Expect is in the public domain. There is full support for Linux and Windows.

Overview and history website: http://www.nist.gov/el/msid/expect.cfm
Support and download website: http://expect.sourceforge.net/
FAQs website: http://expect.sourceforge.net/FAQ.html

310 questions
5
votes
1 answer

expectk in Debian 9

I am reading the book "Why programs fail" from Andreas Zeller. It has exercises that requires using the Android automation tool (not to be confused with Google's OS). I could download it from the author's website but when I started the android file…
z32a7ul
  • 435
3
votes
3 answers

Using expect to send Ctrl+D to a telnet connection

I want to use expect file for connecting to telnet session automatically, the flow is: when we connect to some IP & port, it will show escape character is ] after that we have to give Ctrl+D I wrote one expect file that sends \x04 for Ctrl+D. When…
3
votes
1 answer

expect script to get its directory ?

a bash script can be BASEDIR=$(dirname $0) but how do I do that in expect script ? If I use BASEDIR=[dirname $argv0] I get the error "invalid command name "dirname".
3
votes
2 answers

expect - how to exit with status code 1 if a command fails?

My goal is to rename a file on an sftp server using expect, AND if the rename fails, to exit expect returning a status code of 1 My expect script works fine - it successfully renames. I cannot work out how to exit with a status code if the rename…
Duke Dougal
  • 1,025
  • 4
  • 18
  • 28
3
votes
1 answer

Expect command with multiple commands

Since I have issues with my remote server [authorized_keys...] I wrote a script on my local machine that uses expect command to ssh into the server and then perform cd and then git pull But I can't get this thing to work: #!/usr/bin/expect spawn ssh…
Broshi
  • 161
2
votes
2 answers

Exiting an Expect Script

I have this expect script, that will log into a host, run a command, return it's contents and exit. What sort of cleanup/proper exiting needs to happen when I've finished running my command? This command will always return something, the larger…
Kahn
  • 1,702
  • 2
  • 20
  • 39
2
votes
1 answer

How to spawn expect process with complicated syntax?

In expect it is possible to spawn a process like, spawn /usr/bin/sftp "$uri" /home/user/dest Writing it like this makes things really simple, it will be a one liner. However, I am trying to replicate this for upload. This is a bit more…
patrik
  • 165
2
votes
1 answer

Expect script multiple Q/A

I have the following expect script: #!/usr/bin/expect set timeout 20 set cmd "/path/vpntool --server 1.2.3.4:443 --vpnuser user" set password [lindex $argv 0] eval spawn $cmd expect "VPN:" send "$password\r"; interact expect…
2
votes
1 answer

How to make an expect script to expect either of multiple texts

Below is a sample snippet, normally it works fine unless we passes some command which shutdown the server or cause a disconnection . To handle this, is it possible to expect either "#" or eof after sending the cmd . send "${_cmd_}\r" expect…
Bharat
  • 814
2
votes
1 answer

Expect script to automatically log in, command and show its output

I'm new to scripting and need some help. I am creating an expect script that from a Linux server, that will automatically ssh/log in to our HP StoreOnce Appliance #!/usr/bin/expect -f set password "password" match_max 1000 spawn ssh -o…
2
votes
1 answer

Need Modifications in my expect script

I have an expect script which performs an SSH to a list of servers with the credentials mentioned in the script. It is not throwing any error when it is unable to SSH to a particular server and continues with the next server in the list. I want the…
2
votes
2 answers

How to write expect in shell

This is continuation to my previous question :Spawn command not found After referring to few old posts, I have written those commands, If its wrong, then how I can run ssh to remote server and run some commands ?
dbain
  • 77
2
votes
1 answer

Autoexpect hangs at the end of the script

I have an autoexpect script. I modified it and it works great, however when it finish to run it hangs and I need to do ctrl+C in order to get my terminal [..] 887VA#logout Connection to 10.255.255.1 closed by remote host. Connection to 10.255.255.1…
Federi
  • 963
  • 8
  • 27
  • 38
1
vote
0 answers

Expect can not expect the output

I have problem with my simple code, the expect can not expect the output set timeout 10 set user username set password password spawn ssh $user@000.000.000.000 expect "Password:" send "$password\r" expect eof send "cv mk ghassan-test-5\r" sleep…
1
vote
0 answers

How do you shut down an expect script in the presence of a complex shell interface?

I am running zsh inside of tmux with prezto, and a basic expect script is exiting improperly: set timeout -1 spawn $env(SHELL) expect -regex ".*" send "echo 'foo'\r" expect -regex ".*foo.*\r" send "^D" expect eof What happens is the foo is output…
Chris
  • 961
  • 7
  • 20
1
2