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 and security maintenance. It has a particularly powerful response recognition.

Expect adds many extensions to the Tcl scripting language which simplify scripting interactive applications controlling such hard-to-interact programs as, for example, 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.

Links

Common "gotcha"s

Take careful note of this caveat from the expect(1) man page:

Expect takes a rather liberal view of scoping. In particular, variables read by commands specific to the Expect program will be sought first from the local scope, and if not found, in the global scope. For example, this obviates the need to place "global timeout" in every procedure you write that uses expect. On the other hand, variables written are always in the local scope (unless a "global" command has been issued). The most common problem this causes is when spawn is executed in a procedure. Outside the procedure, spawn_id no longer exists, so the spawned process is no longer accessible simply because of scoping. Add a "global spawn_id" to such a procedure.

Debugging Mode

The expect program has a debugging mode where it prints out exactly what it receives from the spawned programs and what it is looking for. This can be extremely helpful when working out why your scripts are not working! Enable it by passing the -d option on the command line.

2733 questions
0
votes
1 answer

How can I account for connection failure using expect for ssh log-on automation?

I have a shell script that works fairly well for automating my ssh connections and for anything else that I would like to do via ssh. I'm very unsatisfied with the results, however, when host can't be found or if connection is refused. If the host…
0
votes
1 answer

Expect Script - For Loop - How to use more than 1 variable

How can I use more than 1 variable in expect script "for loop"? Please help. Thanks in advance. With one variable: for {set i 1} {$i < 256} {incr i 1} { } How can 2 or 3 variables, say init , condition, increment of i, j, k ? comma, semicolon is…
Krishna
  • 3
  • 1
0
votes
1 answer

Can I pass bash arguements to an expect environment?

I need to automate an openvpn connection to a server that requires me to enter a password. I can do this with expect but I don't want to keep the password in plain text in the script. I found encpass to help encrypt the password which I just need to…
0
votes
2 answers

Yubikey with expect not accepting password

I have recently purchased my first Yubikey and I am using the ykman oath code command on Centos 7 to show the passcodes stored on this key. I have put a password on the yubikey which must be entered to see the appropriate oath codes. I am trying to…
0
votes
1 answer

expect script answering questions interactively

I want to create a script which i will use to generate some reports, but to do that i have to answer few questions, which being asked by other script i run (already located in destination server in /tmp) The answers can be yes, no, for some…
Alxta13
  • 11
  • 4
0
votes
2 answers

Read a keypress in Expect script

I'm newbie with Expect and need a simple functionality: wait for a user to press ANY key and then continue the flow. What command in the script should I use for this purpose ? Thanks.
Mark
  • 6,052
  • 8
  • 61
  • 129
0
votes
2 answers

Calling `expect` from Python without a separate file

I have the following expect file that I would like to embed in a python script. Currently it is its own separate file that I call from my python script, but I would like to merge the two: do_remote.sh #!/usr/bin/expect spawn ssh -i priv.key user@ip…
Michael Bianconi
  • 5,072
  • 1
  • 10
  • 25
0
votes
2 answers

how to use caret ^ in expect statement

I want to use ^ in an expect script just like in the shell: grep '^god'. Running: echo -e "abc god 1st line\ngod 2nd line" | grep ^god Returns: god 2nd line But ^ seems not to work when run in the following expect script: spawn myscript expect…
Max
  • 15
  • 4
0
votes
0 answers

Expect 'send' not working when file is executed

I use Docker to build an image and within that image, I have a .exp file I run to authorise the installation of some software which requires user input in the terminal. When I send a value after using send nothing is printed in the command line…
steve
  • 797
  • 1
  • 9
  • 27
0
votes
1 answer

Expectj - Getting everything that has been received on the spawn's stdout during this session

I am using Expectj 2.07. I am trying to use getCurrentStandardOutContents() to print everything that has been received on the spawn's stdout. public class ExpectTest { public static void main(String args[]) { ExpectJ expectInit =…
tuk
  • 5,941
  • 14
  • 79
  • 162
0
votes
1 answer

expect usage after ssh connection

I am able to use expect to connect automatically with SSH. However, I have a lot of shell commands and shell conditions to be executed or tested after the connection. I am wondering how I can deal with this situation. It looks like putting the shell…
Qiang Li
  • 10,593
  • 21
  • 77
  • 148
0
votes
1 answer

Shell script output is incomplete

I was debugging the expect script wherein i came across a line which was giving me incomplete output. ./worldbox.exp 30.30.30.30 username password 7 > /tmp/30.30.30.30.txt For value 7, the code in worldbox.exp looks like below. elseif…
Murali Go
  • 29
  • 8
0
votes
1 answer

Getting error in expect for loop

Expect Script "testscript2": #!/usr/bin/expect set hostlist [open ./host_list] set ipaddrs [read $hostlist] foreach line [split $ipaddrs \n] { spawn scp id_dsa.pub root@$line:~/.ssh set pass "abc123" expect { …
Brian
  • 1
  • 1
0
votes
0 answers

In shell script, how can I get the output from an expect block?

Hi I am new to shell script and I am having trouble using Expect command. I can't get the output for the command I executed in expect block. I have a ssh script that will connect to a server and check if a log directory exists or not. And if it's…
Kaung Myat
  • 61
  • 1
  • 5
0
votes
1 answer

Unable to spawn ssh using expect in ActiveTcl on Windows PC

The title is similar to unable to spawn ssh using TCL expect in ActiveTCL but I think I'm running into a different problem... I just installed the 32-bit version of ActiveTcl 8.5 on my Windows 10 PC. After installing it, I successfully installed…
gboy
  • 633
  • 1
  • 6
  • 13
1 2 3
99
100