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.

2
votes
1answer
37 views

Remove carriage return (\r) from variable in expect script

Setup Ubuntu 16.04 expect Scripts In the simple script bellow the goal is to simply find the oldest .zip file in a directory on a remote machine using ssh. Then use scp to download this file to the ...
0
votes
0answers
33 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
53 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
25 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 ...
13
votes
4answers
3k views

What happens if I start too many background jobs?

I need to do some work on 700 network devices using an expect script. I can get it done sequentially, but so far the runtime is around 24 hours. This is mostly due to the time it takes to establish a ...
0
votes
1answer
22 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 ...
5
votes
1answer
288 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
29 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
200 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
92 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
138 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
161 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
35 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
57 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
130 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
111 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
248 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
88 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
394 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
31 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
195 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
1k 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
115 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
395 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
122 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
214 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
848 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
366 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
64 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
99 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
468 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
668 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
968 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
414 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
463 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
64 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
329 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
246 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
580 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
355 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
256 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
417 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
220 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
82 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
56 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
199 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
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 ...
1
vote
1answer
283 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
2k 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 ...