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.

61 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
2answers
868 views

When using expect: SSHFS Transport endpoint is not connected

When I run my SSHFS connection script from bash, everything works perfectly. However, when I run the same script using the expect utility, I get the following error when I try to access the folder ...
3
votes
2answers
4k 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}" ] ...
3
votes
0answers
231 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. ...
2
votes
1answer
389 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/...
2
votes
0answers
89 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 ...
2
votes
1answer
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/...
2
votes
0answers
289 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 ...
2
votes
0answers
1k 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 ...
2
votes
2answers
890 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 ...
1
vote
1answer
41 views

How to write an “expect” script that checks if the supplied password matches one of multiple possible passwords?

I want to change the password on my server. There are four possible passwords that should all be accepted for changing a password on the server. To achieve this I want write an "expect" script ...
1
vote
0answers
130 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 ...
1
vote
0answers
87 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) ...
1
vote
1answer
213 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 "...
1
vote
1answer
1k 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 ...
1
vote
1answer
5k views

How to check whether a given path is a file or directory

I am using the command below in my expect script (in tcl/Tk) for checking whether the entered path is an individual file or directory: set b [exec ./check.sh $file1 | awk -F {=} {{print $1}} ] The ...
1
vote
1answer
453 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 ...
1
vote
0answers
152 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 ...
1
vote
0answers
395 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 ...
1
vote
0answers
908 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/...
1
vote
1answer
1k views

`Interact` not working as expected in bash/expect scripting

In order to provision an embedded device (i.e. writing images to flash) a series of very well known commands have to be entered during the boot stage. The algorithm is something like: Capture a ...
1
vote
0answers
15 views

Configuring an alert when a program tries to interact with the user

Most programs in *nix-land take their options via the command line or through a configuration file. However, there are a few programs that do not have any such option, and will resort to interacting ...
1
vote
1answer
1k views

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 ...
1
vote
0answers
298 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. ...
1
vote
1answer
7k views

set variable in bash script with EXPECT

I have a bash script which can login to Cisco switch and shut/noshut any port I have defined in it. What I want is that I can add variable, like I can define port number in a command like this: ./...
1
vote
0answers
552 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 user@192.168.1.1 ...
1
vote
0answers
870 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 [...
1
vote
1answer
393 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 ...
1
vote
0answers
2k 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=...
1
vote
1answer
2k 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 ...
1
vote
0answers
597 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 $user@000.000.000.000 expect "Password:" send "$password\r" ...
1
vote
1answer
599 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 ...
1
vote
2answers
2k 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: ...
1
vote
1answer
1k 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 ...
0
votes
1answer
19 views

'expect' not matching server response string

I'm using a bash script to log into a telnet server and execute a number of commands. It looks like: login_and_run.sh #!/bin/bash unset TELNET_USER_NAME_STRING unset TELNET_PASSWORD_STRING unset ...
0
votes
0answers
58 views

how to send special characters in expect script?

I'm trying to send special characters (password) which contains #?!k;|C . these password is dynamic and cannot be hardcoded in script. so I'm passing through variable as below $ expect ./...
0
votes
0answers
44 views

Unix - Expect Shell - Syntax for using ifcondition on while loop

I have been working on a expect script on AIX OS. The script should pick the server list from input file from while loop and proceed with an if condition to match a specific pattern then proceed. else ...
0
votes
1answer
62 views

Control a bash instance by a script (in a robust way)

I'd like to control some bash programs (local, or ssh) with some (eventually interactive) scripts (say python) in a robust way. I'd like to send commands, get the stdout/stderr of that command at the ...
0
votes
0answers
33 views

How to switch user in the server by su without password through shell script?

I am using cygwin to run my expect command for login into server. Once login i have to switch the user by su command writing password in the shell script which does not prompt for password and ...
0
votes
1answer
30 views

Manually enter password into expect and use as variable while scrip is running

I have an expect script that uses interact every time a password is needed. The program that expect is automating asks for the password multiple times. Is there a way to only have to type the ...
0
votes
0answers
35 views

File Movement between server's that have the same case-insensitive filename

We have a table contains the file name's which are considered as inbound feed every week and one of the file name is as below File_name : FEB_MERC_DATA_??????.txt Sample inbound file which we got in ...
0
votes
1answer
553 views

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".
0
votes
2answers
149 views

When sed is used in an expect command, what is the proper way to escape the backslashes?

I currently have the following code for an automated ssh script: #!/usr/bin/expect -f set pw "mypass" spawn ssh user@login.address.com expect "Password:" send "$pw\r" expect "Verification code:" ...
0
votes
2answers
515 views

Expect in bash script?

Is there a way to use expect command directly in a bash script for which the automation is to be done, instead of writing a expect script and use spawn command to trigger the bash script from expect ...
0
votes
2answers
2k views

Expect script connects with ssh but does not run commands

I need to write a script that runs on a PC with Centos 7 and connects to another PC with Centos 7 using ssh, execute a console command, for example "ls -la" and save the output of it to a file to be ...
0
votes
0answers
621 views

Run expect script which spawn screen over SSH - Set terminal type

I have an Expect script which spawn a screen session to read an embedded board console and give respond automatically. I have no issue while executing the Expect script locally in the host. But when ...
0
votes
1answer
497 views

Unix shell script using Expect shell

Im writing a script to collect micro code levels for adapters on each servers in AIX, using Expect shell. #!/bin/ksh for hostname in ABCD123 ABCD234 ABCD445 do expect << 'EOS' set hos {$...
0
votes
1answer
59 views

Telnet connection Procurve switch

Im writing a script to get a dump of the Procurve switch-settings I start the script like this: ./script.sh | tee /home/user/telnet.log Here the Script #!/usr/bin/expect -f set timeout 20 set ...
0
votes
1answer
25 views

Bundle Expect library with shell script

I want to create a shell script that uses the Expect library however Expect is not installed on any of the systems where I want to run the script. Can I build Expect from source and then put in same ...
0
votes
0answers
70 views

expect script to automate utility

we want to automate the utility - "Setup ambari-server" this utility ask 4 default questions , and all answers should be default (no) how to use expect script to automate this utility ? ambari-...
0
votes
1answer
289 views

Expect command not working with proxychains in Linux

I am writing a small script using expect command to supply the password; the aim is to login to a switch and fetch a command. OS : RHEL 7. There is a small app proxychains which is used to login to ...