Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
1answer
182 views

Unix AIX passing variable and arguments to expect and spawn

I am writing a script to scp some files but need to pass file location through the user or another script as an argument #!/usr/bin/expect set FILEPATH1 $1 spawn sh "scp $FILEPATH1 $USER@$HOST:/...
0
votes
0answers
23 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 ...
2
votes
1answer
151 views

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:" ...
0
votes
1answer
78 views

Commands leaking characters to bash

While building a small expect script I noticed that, after executing the script, some characters were automatically on the input of bash. I have seen that on other programs before, but here I have ...
1
vote
2answers
75 views

How can I “source” expect script

I'm forced to use a script like below: # test.sh function my_fun { echo "Give value for FOO" local my_var read my_var export FOO=$my_var } # Call my_fun function my_fun by sourcing ...
0
votes
2answers
99 views

Tcl script with multiple spawn expect and send

I am trying to automate the installation of certificate(s):q! in jboss server. i wrote this rudimentary script: #!/usr/bin/expect set Temp_Dir "/tmp/install" set jboss_sec "/opt/jboss/security" set ...
0
votes
1answer
22 views

Variable file in Expect script

I'm using this expect script as an answerfile to a interactive shell script: #!/usr/bin/expect spawn ./interactivescriptname expect "Question 1?" send "something\r" expect "Question 2?" send "yes\r" ...
0
votes
1answer
42 views

How to execute command under if statement in Shell Script under expect condition?

send "if [ `ps -ef | grep ttyS1 | sed -n 1p | cut -d ' ' -f 2` -eq 'ttyS1' ]; then not_found='false' else not_found='true' fi\r" I have tried so many time with double quote and single quote also ...
1
vote
2answers
98 views

Automate variable number of inputs in for script

I understand these 3 options for automating an interactive script: Pipe answers to executable eg. yes '\n\n\n\n\nY\n' | ./script yes command to pass the same reply to all questions expect to provide ...
0
votes
1answer
77 views

autoexpect script.exp

I use autoexpect generated a script.exp. see following. how to understand expect -exact " \r Type ha for help on aliases\r \r ]0;luoric@linux-pc-64:/home/luoric/tmp[01;34mluoric@linux-pc-64[01;34m ...
1
vote
3answers
187 views

Reading variable from another file into bash

I have written a bash script which calls other process (the ones that ask for password on terminal). #!/bin/bash source pc.txt snp_pw=$export_snapshot export snapshot_pw=snp_pw echo_time() { ...
-1
votes
2answers
63 views

How can I ssh into multiple password protected machines to reboot them?

I'm trying to write a bash script to reboot multiple machines via ssh that are all password protected. I have all the IPs listed in a .txt file and want the script to read the IPs from there. I've ...
0
votes
1answer
253 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
1answer
29 views

File Permission - Only let script read?

I have a password stored in plaintext. I only want my expect script "LoadList" to be able to read the password in order to spawn an SFTP session. There's no scenario in which I want to be able to read ...
-1
votes
3answers
136 views

How can I avoid this error “couldn't execute ”des“: no such file or directory”?

I'm trying to do encryption in Expect as outlined in this wiki on Ubuntu 16.04. I've installed tcllib root@alarmux:/home/abdmin# apt-get install tcllib Reading package lists... Done Building ...
0
votes
1answer
923 views

Expect script error- extra characters after close-quote

Error while executing send if command, Not sure if I'm missing some tcl syntax. #!/usr/bin/expect -f # Get the list of hosts, one per line ##### set f [open "/tmp/host.txt"] set hosts [read $f] ...
1
vote
0answers
91 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 ...
4
votes
1answer
348 views

Pass variable to spawn [duplicate]

I want to pass server name which is listed in a file (servers_list) as variable to spawn command which is in another script (user_create_script). Purpose of this script is to create user(david) in ...
0
votes
2answers
103 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:" ...
1
vote
0answers
150 views

Create new file after `scp` in remote script [closed]

Learning bash and trying to copy a file from a local machine to a remote machine. I would like to create a simple .txt file on the local machine that logs a success. This is my first foray into bash, ...
1
vote
2answers
541 views

How do I use 'expect' to read the contents of a file into a variable?

I am having troubles writing an expect script. I want to do something equivalent to the following bash instruction: iplist=$(cat iplist.txt) I've tried using set in all the ways that I know but it ...
0
votes
2answers
221 views

Monitoring of disk space on multiple Linux server using expect script

I'm trying to write a script using Expect for monitoring multiple servers; the connections will be through ssh using a password. My basic loop is self failing, I'm not sure whether Expect TCL ...
0
votes
1answer
40 views

How to output multi-page output in expect to file without option prompts being logged

I have a script using expect to run some commands on machine over SSH. There is a part of script which issues a commands that causes multi-page output that I want to have saved to file. How can I ...
2
votes
1answer
83 views

Expect wigs out when I use the single quote in [exec ls -h | grep '\.foo' ]

I am trying to store a list of specific files into a variable in expect. In my script, I am trying to compile files that have different file extensions, like .foo, .bar. In this example, I have the ...
0
votes
2answers
428 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 ...
-2
votes
1answer
540 views

Use of expect to run scripts on remote machine

I have automated most of the information required for the completion of this project but the only thing that is lagging is the running of local shell scripts on the remote machine. As we are aware ...
2
votes
2answers
656 views

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 ...
2
votes
3answers
346 views

How to escape a character in a heredoc bash script

I have a bash script which read an input file and using a heredoc to ssh to a server using expect, but am having issue escaping some special character in the input file. Here is what I have.. I have ...
1
vote
1answer
349 views

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

answering command automatically - performing cp operation between answers [closed]

The idea is that I want to execute a command, then it asks for a file name to process, and after it is done with processing, it outputs an image with the name prediction.png, it asks for the next ...
0
votes
2answers
1k 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 ...
2
votes
1answer
281 views

Expect script is returning errors when spawning bash script. Why? [duplicate]

I am testing out Expect to get a basic template working. I have created a demo bash script which asks a few questions and outputs the inputs to a file. When I execute the .exp file directly or ...
-1
votes
1answer
229 views

ansible and continue the script with expect tools

My expect script: #!/usr/bin/expect -f set timeout 1 spawn /opt/install.sh expect "\[input\] Are you installing the application at the central data center? \[yes/no default: yes\]? \[yes\]\r" ...
0
votes
0answers
523 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 ...
1
vote
2answers
338 views

expect not taking ssh arguments in while/for loop

I'm trying to fetch remote machine details (dmidecode) for many hosts using some expect command. Below is the expect script which I'm using for this purpose. while read i; do { /usr/bin/expect<&...
1
vote
1answer
216 views

Expect, Command, Pipes and Gzip

I am trying to work with the expect command, everything works well until I try to pipe the results of a command into a Gzip file. Here is the snippet of the bash file: XYZ=$(expect -c " spawn python ...
0
votes
1answer
357 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 {$...
5
votes
1answer
200 views

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 ...
1
vote
0answers
76 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) ...
0
votes
1answer
52 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 ...
1
vote
1answer
182 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 "...
0
votes
1answer
24 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 ...
1
vote
1answer
268 views

executing linux script with options in expect

I am executing Linux script in expect mentioned as below. spawn "sh /opt/Avaya/CCR/util/CAT/cat.sh --iptfile=no" I am using ansible to execute above command . when I execute ansible-playbook ...
2
votes
1answer
1k views

Expect script to ssh into a remote host and change its password

So recently I have been working on a small script that will login to a remote unix host and change its password, I've never had much experience with expect so its been an upward learning curve. The ...
0
votes
0answers
67 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-...
1
vote
1answer
2k views

How to pass parameters to EXPECT using the '-c' option?

I'm using expect inside my bash script by using expect -c, but how do I pass parameters to it? This is what I've tried: FILE="myFile" HOST="myhostname" /usr/bin/expect -c $FILE $HOST ' set ...
0
votes
1answer
30 views

Working with expect command

I have an installation script that gives out the following prompt: Please type a selection or press "Enter" to accept default choice [1]: I cannot make expect catch it. I tried to play around the ...
3
votes
1answer
272 views

Expect to automate yes answer to CLI

When I run the command ambari-server upgrade from a bash script, in the middle of the upgrade we get the question have made a backup of the Ambari Server database [y/n] (y)? so we want to automate ...
0
votes
2answers
4k views

How do I spawn a BASH command in expect?

I have an expect script, and want to spawn a BASH command for it to provide input to. When I use the following syntax: spawn /bin/bash docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ...
1
vote
1answer
430 views

Define input number with expect

I am trying to automate the deployment of a Docker container. Three prompts need to be filled in manually in order to proceed with the deployment. However, they are not to be filled in after each ...