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
1
vote
1answer
17 views

Parse the output of an expect variable and use it in a bash script

I have a bash script that uses expect inside the bash script. This bash script will prompt for a password inside the expect part of the script and then return some output. I want to take that output ...
1
vote
0answers
31 views

How to run function in remote server using ssh and expect [closed]

I need to run a function on a remote server over SSH. I'm using expect to automate login to remote server. On remote machine, I can run command, local scripts, but function is not working. I get "bash:...
0
votes
1answer
31 views

Expect command: Setting multi-line environment variable of host

So I have an RSA token set in my environment variable. I want to set it in the environment of the remote machine. I tried this below script to set, but it only sets first line -----BEGIN OPENSSH ...
0
votes
1answer
41 views

Unix Shell script using expect

I am new to using expect. I am running the below code to get the token from a server: set timeout 20 set token "" sleep 1 spawn ssh -l $serveruser1 $serverip # -- is used to disable the ...
0
votes
0answers
10 views

expect redirect incomplete output in rhel 7.5

Can any one help me out with redirecting shell out. [root@localhost automation]# vi cs300.sh #!/usr/bin/expect -f set timeout -1 spawn ssh Monitor@172.30.19.96 expect "Password" send "Password\r" ...
0
votes
1answer
16 views

Expect - parse all occurrences of a pattern and store in a variable

I am trying to process multiple mac addresses from output of a program. Output is in below format - Device B0:CA:68:CF:88:54 dev1 Device DC:16:B2:AE:FB:8F dev2 Device B0:CA:68:CF:88:11 dev3 Device DC:...
0
votes
1answer
54 views

Expect script to download newest file from remote server with grep

I have an expect script to download the lastest database backup from a remote server. I am new to shell/expect scripting and I am struggeling with storing a clean filename from the output buffer in a ...
0
votes
1answer
38 views

Not Getting output of Expect Script in Crontab

I've created an Expect Script (.exp) to get the raw file in other server. Then, I also have .sh file to call my .exp. It's working well when I tried to run it in a usual way (./call_expect.sh). But ...
0
votes
1answer
58 views

I need to ssh into another machine using expect and a password and start a program there, then start a program on my local machine. How can I do this?

As said in the title, I am writing a script that should run on Computer A. Computer A should ssh on Computer B, run Program B, then exit the ssh session (Program B still running on Computer B) and ...
0
votes
0answers
24 views

Repeatable Options Expect/Bash Telnet Listener

Hey guys first time post. Trying to determine if it is possible create a bash/expect file combination that can serve as a Gameserver Moderation Bot. It spawns and listens on telnet. It would ideally ...
2
votes
2answers
69 views

Expect script embedded in shell: how to specify value defined in remote shell?

1. Problem description: I have a script which needs to ssh to an remote server and run some scripts. But I met some troubles when trying to use values that defined in remote server. I use "\$" to ...
1
vote
1answer
28 views

Executing stdout results line by line that has a prompt confirmation

I have a command that (potentially) prints several lines and then I want to execute them one by one (using xargs for example, or anything else): find . -name "*string*" -print | awk '{ print "echo " $...
1
vote
1answer
141 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 ...
0
votes
1answer
90 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
1answer
715 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 ./...
3
votes
1answer
67 views

Bash program terminates after a few seconds

I have written a small script to download files from an FTP to external drive that is connected to my Raspberry Pi 3B+. I am using rsync to download my files. Here are the scripts: download.sh: #!/...
1
vote
1answer
234 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 ...
0
votes
1answer
144 views

Cron to Bash Script to Bash Script to Expect Script

I want to execute a series of Expect scripts. The chain of execution goes like this: Cron job starts a bash script, this wrapper starts ~11 bash scripts in Parallel - each of them call an Expect ...
0
votes
1answer
397 views

Calculating packet loss from ping?

I've got an ESXi VM that does command execution on some 700~ devices on our network. It's using Expect, and due to the age of this equipment they have periods of poor performance. These two don't mix ...
2
votes
1answer
457 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
93 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
74 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
53 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
4k 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
97 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
628 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
65 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
295 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
206 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
3answers
654 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
326 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
243 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
176 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
204 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
511 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
1k 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
376 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
1k 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
34 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
450 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 ...
1
vote
1answer
3k 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
187 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
698 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
237 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:" ...
2
votes
2answers
3k 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
1k 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
138 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
205 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
722 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
1k 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 ...

1
2 3 4 5