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.

75 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5 votes
2 answers
7k views

Log the output of Expect command

I have made the below expect script and I need to log the output of that script. SOURCE_FILE=`ls -l *.txt --time-style=+%D | grep ${DT} | grep -v '^d' | awk '{print $NF}' ` if [ -n "${SOURCE_FILE}" ] ...
sabarish jackson's user avatar
4 votes
0 answers
454 views

unbuffer/expect swallows the rcode when its child is signaled

unbuffer is able to pass along the return code of a process under normal circumstance, but if the process you are unbuffering is killed, for instance with a segfault, I see $? as 0 while I expect 139. ...
frankc's user avatar
  • 141
2 votes
0 answers
71 views

Waiting until an application is reading (over a TTY)

I'm writing an expect-style program to interact with a command-line application on Linux. Is there any way that my program can know when the application on the other side of the PTY tries to perform a ...
Subhav's user avatar
  • 21
2 votes
1 answer
494 views

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 ...
patrik's user avatar
  • 165
2 votes
0 answers
346 views

not run expect script in ansible

my script is : #!/usr/bin/expect set timeout 1 spawn /etc/init.d/oracleasm configure expect "Default user to own the driver interface []:\r" send -- "grid\r" expect "Default group to own the ...
pyramid13's user avatar
  • 639
2 votes
0 answers
169 views

Using lpass to unlock an ssh key

I'm using the Lastpass CLI (lpass) and want to have it give the passphrase for a private key direct to add-ssh on login as part of .bashrc . the net effect is that I login to Lastpass on when I start ...
Nate's user avatar
  • 121
2 votes
1 answer
1k views

Expect PECL for PHP 7

I just upgraded to PHP 7.0.3, but there is no support for expect. Does anyone know if is it possible to bypass the installation issue? It says: root@portal:/home# pecl install expect-0.3.3.tgz pecl/...
Erik Figueiredo's user avatar
2 votes
0 answers
341 views

Tcl/Expect: Can't set variable value correctly

I'm trying to get IPSec tunnel details from the router. After that fetch lines with IP addresses. So, I have follow code: send "show tunnel ipsec remote 10.10.10.10\r" expect "local" send "\r" set ...
ZhKSteaL's user avatar
2 votes
0 answers
2k views

Installing Expect and TCL

I downloaded the source for expect5.45, and am attempting to install it. tclsh is on the system at /usr/bin/tclsh, but I'm not sure if that means the machine also has "tcl" installed? The ...
user avatar
2 votes
0 answers
3k views

bash - expect and variables

I have the followin: while read line; do userinfo=$(echo $line | sed 's/@/,/') IFS=',' read -a address <<< "$userinfo" userid="${address[0]}" domain="${address[1]}" fname=...
user68650's user avatar
  • 343
2 votes
1 answer
3k views

Expect script + automated telnet process between three Linux machines

Is it possible to do the following by expect script? I have Linux server that connected to linux_machine1 and linux_machine1 connected to linux_machine2 My Linux server have access only to ...
user avatar
2 votes
2 answers
1k views

Regular expressions with ExpectJ

I've been used the ExpectJ Java library to automate some jobs on a Linux server, however now I need to automate a job that sends a different text response for each execution. Here is the output: Last ...
fers's user avatar
  • 59
2 votes
1 answer
3k views

Send command to already running process in shell script

In bash how can I issue a command to a running process I just started? For example; # Start Bluez gatttool then Connect to bluetooth device gatttool -b $MAC -I connect # send 'connect' to the ...
sazr's user avatar
  • 241
1 vote
0 answers
151 views

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 ...
Chris's user avatar
  • 961
1 vote
0 answers
186 views

Running expect in systemd unit causes sh syntax error

I am trying to automate the process of connecting to my VPN (SonicWall NetExtender) from my Linux machine by using a systemd unit to call an expect script that supplies the login credentials to the ...
MrDrMcCoy's user avatar
  • 121
1 vote
0 answers
195 views

Catching the query results executed in the remote PostGreSQL server through expect command inside Python script

I want to catch the PostGres query results that gets executed in the remote server (passwordless-ssh) via expect command that is used to supply the password for the given PostGres user. Actually, ...
Ibrahim Quraish's user avatar
1 vote
0 answers
176 views

Upstart script with expect scripting

Please give me advices about expect scripting combined with an upstart script. There are 3 scripts that I am dealing with right now. Script A) Java program PATH: /opt/~~/manager Script B) ...
user286310's user avatar
1 vote
1 answer
411 views

Expect output use

I made a script and it looks like this: #!/usr/bin/expect -f set ip [lindex $argv 0]; spawn ssh name@server expect "assword" set timeout 0.5 send "password\r" expect "xxxxx" set timeout 1 send "...
inscripted's user avatar
1 vote
1 answer
3k views

expect: get error status when spawn command fails

The below is the sample of a script which we execute daily for getting info from the server. For the last couple of days, some server data is missing from the output which is captured on the local ...
Shanker's user avatar
  • 117
1 vote
1 answer
2k views

How to make a script "wait" for an operation to finish?

I have two scripts, or maybe better call one a wrapper for the another. Here comes the wrapper: #!/usr/bin/expect set timeout 20 spawn "./installOracleDatabase.sh" expect "replace Disk1/upgrade/...
Zibi Smough's user avatar
1 vote
1 answer
861 views

Multiple telnet connection in Expect while loop

I need to get the serial number of some devices listed in a file like this: device_id,ip_address BIOTERIO, 148.000.00.189 N7K-LAN(JAF1651ANDL), 148.000.0.192 LAB_PESADO, 148.000.000.130 ...
Cesar Alejandro Villegas Yepez's user avatar
1 vote
0 answers
384 views

Shell script to correct authorized key file permissions in large number of hosts

I have a large number of systems that I need to connect to (hosts.txt) and update permissions of the authorized key file prior to pushing keys out to the systems. I inherited the files that can push ...
KevinJ's user avatar
  • 11
1 vote
1 answer
980 views

Extract contents of jar file to curl using scp

I have a jar file containing a javadoc tree on one box. I need to transfer it to another box and unpack the jar in a specific directory (which may not exist). I have the username/password of the ...
David M. Karr's user avatar
1 vote
0 answers
2k views

Expect script seems to ignore prompt (RSA fingerprint confirmation)

The following script seems to simply ignore the rsa fingerprint/continue connecting prompt. I have tried different things, but I simply cannot figure out why it is not working as expected. #!/usr/bin/...
Michael Weber's user avatar
1 vote
0 answers
580 views

Start a subshell then run commands

Say I have a script that is always run from an interactive shell. I would like this script to launch an interactive subshell that is a replica of the parent (i.e., all environment variables, etc. ...
Xophmeister's user avatar
1 vote
0 answers
616 views

whether the ssh command successful or not?

I spawned ssh in expect script. in the script i have to check the exit status of ssh command on local machine to make some condition in that script using if/else. spawn ssh [email protected] ...
al mamun's user avatar
  • 123
1 vote
0 answers
1k views

Why the output is not written to log from expect script

I am trying to write the output of the netcat command including the command also to a file by logging into remote servers. But it is not writing. What am I missing ? #!/usr/bin/expect -f set user [...
Novice User's user avatar
  • 1,349
1 vote
1 answer
535 views

Automating setup of the SSH tunnel

I need to frequently login to many machines but I can only login to them from a proxy machine or using an SSH tunnel (by tunneling through that proxy machine). The problem is that I cannot use ...
syntagma's user avatar
  • 12.3k
1 vote
0 answers
677 views

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 [email protected] expect "Password:" send "$password\r" ...
Ghassan Shawahneh's user avatar
1 vote
1 answer
709 views

Is expect tool availabe for ARM platform

I need to get expect (tool for automating interactive applications) for the ARM platform. Is it a readily cross compiled to ARM and is it available? I tried googling but was unable to get the ...
m4n07's user avatar
  • 191
1 vote
2 answers
4k views

expect script for getting output for multiple servers

I am trying to get output of IQN from multiple servers. I am getting the below error. Error output spawn /usr/bin/ssh VM2 | /usr/bin/cat /etc/iscsi/initiatorname.iscsi root@VM2's password: bash: -c: ...
user avatar
0 votes
0 answers
311 views

expect script terminating early in Dockerfile

I've got an expect script that I need to run in a Dockerfile. However, the script is terminating after all of the input is sent. What's interesting is that docker build is succeeding. Here's my MRE:...
Daniel Walker's user avatar
0 votes
1 answer
1k views

adding ansible_python_interpreter to task with expect module fails to get command with become_user

I'm writing a task for CentOS7 inventory in which have to go through prompt dialogues, which I think is best candidate for andible's expect module. - name: setup some command become: yes ...
Sollosa's user avatar
  • 1,929
0 votes
1 answer
34 views

How does one use Expect with Git interactive CLI w/out resorting to alternative strategies?

Typically, I can use the expect mechanic of expect followed by send. In the case of git's interactive shell, however, this does not work and I must use puts. Is there some trick to restore the normal ...
Chris's user avatar
  • 961
0 votes
0 answers
67 views

How can I execute command that has three and/or optional answers in sequence?

I have command to execute: "sudo ssh -L 80:localhost:80 -f -N [email protected]" There are three options that in some case I get them and some not: password for jenkins user: "[sudo] ...
Y.K.'s user avatar
  • 1
0 votes
1 answer
194 views

Using expect to write a bash script

I am trying to write a bash script using expect. This bash script will reside on a remote server, to be executed at a later date/time. I am using expect to read in a large data file, perform some ...
Mike's user avatar
  • 1
0 votes
1 answer
52 views

Sending bunch of commands from txt file in Expect

How to send bunch of commands to Cisco router from txt file like: configure class-map match-any popc_fiberpower004_booster_v4 match access-group ipv4 bng_permit_v4 match access-group ipv6 ...
wrkilu's user avatar
  • 1
0 votes
1 answer
866 views

How to send variable value in send command of expect script

Below is my script proc sendline {line} { send -- "$line\r" } set slot 1 set port 1 for {set x 0} {$x<48} {incr x} { sendline {curl -X POST -d '{"command":"dumpcommand&...
user2071089's user avatar
0 votes
0 answers
290 views

zsh, zpty: How to read the output of a process after it has exited?

Start some command with zpty: zpty -d x ; zpty x 'echo hi' ; sleep 1 How do I read its output now that it has exited? zpty -r x Returns 2, and this behavior seems expected per the manpage.
HappyFace's user avatar
  • 1,612
0 votes
0 answers
23 views

Is it possible to carry local RSA keys to remote computer (live) and use securely?

Is it possible to store an SSH-id in some sort of session (like expect or ssh) that is running on the local machine, swing into a remote box, and execute a shell command in the remote box as if the ...
Chris's user avatar
  • 961
0 votes
1 answer
263 views

Load configuration file after ssh using expect

I'm trying to ssh into a remote host, load an environment variable in the .zshrc file on the host, then execute a command using that environment variable. Here's my script so far, #!/usr/bin/expect -f ...
Max's user avatar
  • 101
0 votes
0 answers
332 views

spawn_id is empty when setting

I am running an except script where it spawns a c program, waits for an output from the program, and then spawns another program. After that program has finished, I want to send to the original ...
Kyle Meng's user avatar
0 votes
1 answer
503 views

Problem with 'string match' and variable

I've been searching for hours and trying multiple things. This is the expect code snippet which works. foreach line [split $expect_out(buffer) \r\n] { if {[string match {*word*} $...
Jim.at.work's user avatar
0 votes
0 answers
302 views

Using "expect" command to run an interactive program fails

I am trying to solve my question that I've asked here using expect script instead of file redirection. Unfortunately, this solution doesn't work as well (the same behaviour as described in the ...
adhrar_nmatrous's user avatar
0 votes
0 answers
102 views

sed error on expect script

I am trying to use a simple sed command inside with a expect script spawn sed -n '/0032ff00/,/clogoff/p' /tmp/file.tmp > /tmp/file.tmp1 I get an error: sed: -e expression #1, char 1: unknown ...
Heron's user avatar
  • 1
0 votes
0 answers
112 views

In bash `expect` script autogeneratedd with `autoexpect`, there is a `^G` - what does it signify?

In bash expect script autogen'd with autoexpect,I am invoking line completion with a [TAB] in a situation where line completion offers no completions nor changes the input line. The script excerpt ...
Craig  Hicks's user avatar
0 votes
0 answers
462 views

Run an os.popen command requiring pseudo terminal from python in bash script

I have a python script which uses size = os.popen('stty size', 'r').read().split() to get the terminal window size so I can print text nicely. My problem arises when I have to run this python script ...
CuriousStudent's user avatar
0 votes
0 answers
636 views

expect command not working

Hi all i am trying to automate using expect. I have a custom utility to login to openstack k8 distro the custom command is as below and it asks for an output kubectl-openstack login --server=...
Adam's user avatar
  • 101
0 votes
1 answer
1k views

Exit out from loop on incorrect password in expect TCL shell script

I have written a code snippet in TCL expect to connect from Server 1 to Server 2 using ssh. Users already may have set passwordless communication between Server 1 and Server 2, or it may ask for a ...
newuser's user avatar
0 votes
0 answers
777 views

using expect to ssh 1 host, apply some commands, exit the device and ssh another device to apply some other commands

Hi I'm trying to use expect for network troubleshooting between two devices. in summary, What I'm trying to achieve is to run a script using expect which enters 2 devices and apply commands. the ...
jordi roquet's user avatar