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.

Filter by
Sorted by
Tagged with
0
votes
1answer
58 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
207 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
294 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 ...
0
votes
0answers
69 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
3k 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
41 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
322 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 ...
1
vote
3answers
5k 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
506 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 ...
0
votes
2answers
344 views

Run a local expect script on a remote server?

So I am trying to basically ssh into a server and run a local expect script on there. I tried to follow something similar to how you'd do a bash command i.e. ssh -A user@remote "bash -s" < ./...
0
votes
1answer
286 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 ...
2
votes
3answers
4k views

Convert password with special characters for use with expect script

I have an expect script that connects to an SFTP site and uploads some files. The ID and password are contained in local text files. The expect script reads those files in as a variable and then ...
0
votes
1answer
578 views

Passing parameters by shell script file to expect script

I need to pass a paramter from a shell script under command line of ssh script for example : #!/usr/bin/expect spawn ssh user@servername.com "cm1+passingparameters.sh;cmd2" my existing script 123....
1
vote
1answer
2k views

expect script not working in for loop

Need to login to multiple host I am unable to decide how can we add hostname variable in this script array or list. could any one suggest. And the second thing is that i am getting error while ...
1
vote
2answers
2k views

send special character “~-enter” in expect script

i need some help please. i write a little testing script for my daily work. in that script i will connect to a server console. here is my expect part: export TMPEXPECT=$(mktemp /home/user/tmp/...
0
votes
1answer
1k views

Using expect to execute remote script and get script exit status

I have a script which is on remote server which returns exit status of the script. Now I want to execute that remote script using expect and get the exit status of the script. My remote server script ...
1
vote
2answers
176 views

prompt for an error when no argv is provided expect script

I have to run an expect script for ssh login purpose, but I need to create a file providing the argv while executing the command. When I run this below script file is created. #!/usr/bin/expect ...
0
votes
1answer
387 views

Adding 2 Variable to file in expect script

I am using a expect script & i am unable to set 2 variable to the output file, I just want to name the file as required. #!/usr/bin/env expect set file [lindex $argv 0]; set date [exec date "+%d-...
3
votes
2answers
3k views

How do I expect a newline in expect script?

Consider this interactive script: #!/usr/bin/env bash set -eu while true; do read -p '> ' if [ "$REPLY" == quit ]; then break fi echo "'$REPLY'" done Now I want expect to ...
0
votes
1answer
868 views

Reading expect script commands from file [closed]

I need to update configurations of several gateways...I have two files: File 1 (ip.txt) : Holds gateways’ IP addresses ---> This files gets updated every month. File 2 (cmd.txt): Holds commands to ...
1
vote
1answer
2k views

How to verify, that a DB hive already exists?

We create a hive database using expect script and with some other commands. In the case if we run the expect script again on the machine that hive already created, we get this: ERROR hive already ...
1
vote
1answer
98 views

Run a command based on stdout frequency

I have a program that writes to stdout in a batch of text very quickly, but the output doesn't have a specific output that I can write an expect loop for. Example of stdout of my program: [time:here] ...
4
votes
1answer
791 views

How to send keystrokes before interactive shell to automate Linux serial port login with GNU screen?

I often have to login into Linux devboards with known fixed usernames and password via the serial port. The normal commands are: screen /dev/ttyS0 115200 and then inside screen the session looks ...
1
vote
2answers
9k views

How to redirect output to a log from expect command

I have the following code. How can I redirect the output of the expect to a log file to see if the scp has copied everything successfully. This piece of my code runs in background. export ...
1
vote
1answer
509 views

sed inside expect script send command

I m using sed inside expect script send command as mentioned below and getting the below error. Please let me know what am I missing here. set new '"$Backend1Name"' spawn ssh '"${userid}"'@'"$...
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 ...
0
votes
1answer
531 views

mysql automation through expect

i need to automate mysql_secure_installation process, i have written this script but its failing miserably,, i dont want to set any passwrd for database #!/usr/bin/expect set timeout 10 spawn ...
0
votes
2answers
2k views

Expect script fails when running from cron but works when run manually

I have a script in Linux that creates a file which once created it executes an Expect script that uploads the created file to an SFTP server. I have this running in cron and for whatever reason the ...
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 ...
0
votes
2answers
120 views

How can I update a unique string in a shell-script with the output of a seperate function?

Due to my laziness, I have written an extremely "messy" series of scripts in order to auto-initiate my openvpn. The configuration file I am using comes vpnbook.com/freevpn. To get the password I use:...
2
votes
3answers
756 views

Cat in expect script adds new line to end of string

I have the following in an expect script spawn cat version expect -re 5.*.* set VERSION $expect_out(0,string) spawn rpm --addsign dist/foo-$VERSION-1.i686.rpm The cat command is getting the version ...
0
votes
1answer
419 views

Use expect script from Vagrantfile for provisioning - problem with non existing file during execution

Is is possible to use expect script from Vagrantfile for provisioning? It looks like file inside the installOracle.exp script is not there at the proper moment (see error log): spawn "/var/wminst/...
2
votes
1answer
381 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/...
1
vote
1answer
410 views

expect script giving error

on the remote machine there is one script ./bin/show_info.py which I want to execute and get the output on the local machine, for which i have created a script with expect. If I run the below command ...
2
votes
1answer
1k views

Expect script not sending password as planned [closed]

I've tried reading up on this, but I can't figure out why it's happening. When Expect sends the password it appears as echoed cleartext in the terminal and afterwards "Sorry, try again." appears. ...
0
votes
1answer
5k views

Match a string with a substring in Expect scripting

I have an output like this: Node Name Status IP Address ====================================================== bw2acn0 ENABLED x.x.x.x bw2acn1 ...
0
votes
2answers
283 views

Compose filename inside expect script

I have a file which several lines, let's say: server_file.txt: [main] server1 param1 param2 param3 server2 param1 param2 param3 I want to take the first value of last column to compose a filename ...
1
vote
1answer
399 views

Overwrite file using AWK in a for loop

I'm working on the following script: !/bin/bash FILE1=dispositivoss.csv NUMERODISP="$(wc -l $FILE1 | awk '{print $1}')" for (( c=2; c<=$NUMERODISP; c++ )) do IP=$(awk -vnum="$c" 'NR == ...
1
vote
1answer
5k views

how to make Expect to wait until another script finished

I've got 3 scripts, this is the main one: #!/usr/bin/expect -f #!/bin/sh set DATE [exec date +%F] set IP "148.000.000.101" set Username "user" set Password "pass" set Password_sql "sqlpass" spawn ...
7
votes
1answer
13k views

bash and expect in the same script?

I'm trying to code an script that takes IP addresses from a .csv file and telnet the device to catch "show version" command output. So far I have coded this: #!/bin/bash #!/usr/bin/expect -f FILE1=...
1
vote
1answer
436 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
2answers
6k views

using expect: how to print a message on the screen and not on an opened log file

I have an expect shell, and a log file has to be opened at the beginning, then inside a for loop I want to check certain conditions, if these conditions are met I want to print out a message into the ...
0
votes
2answers
699 views

split an output of a command and search for a word in expect

I have this chunk of code that I want it to read output of a command, substring it from the beginning to a special character and then if that part is not empty send_log that it passed. But I'm not ...
1
vote
1answer
662 views

How can I update my PATH in using expect in a bash script? [closed]

I'm connecting to my university server using ssh. But, every time I log in I have to update my R PATH. So, I would like to automatize it, I have this script so far: #!/usr/bin/expect -f spawn ssh ...
0
votes
2answers
1k views

Command puts in expect doesn't show the message in the order it should

I have a some scripts to automate a process and I want the message about which step I am in it shows in the command window. A piece of code I have is: puts "** Creation of $VMNAME on $HOST begins... ...
0
votes
0answers
590 views

argument not work on expect through command line

Here I have creating script which execute the ansible-playbook, After the execute script which ask the Sudo password which one I have to send(sudo password) though expect and send but getting below ...
1
vote
2answers
2k views

Check for a word in the expect output and add it to a text file [closed]

I have a code like this: #!/opt/tools/unsupported/expect-5.39/bin/expect set timeout 10 match_max 256 log_file report.txt expect_after eof {exit 0} spawn ssh -l user ip expect "(yes/no)?" { send "...
1
vote
0answers
150 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 ...