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
6 views

Load configuration file after ssh using expect

I'm trying to ssh into a remote host, load an environment variable in the .zshrc file on the host, then execute a command using that environment variable. Here's my script so far, #!/usr/bin/expect -f ...
0
votes
0answers
10 views

spawn_id is empty when setting

I am running an except script where it spawns a c program, waits for an output from the program, and then spawns another program. After that program has finished, I want to send to the original ...
0
votes
1answer
17 views

Strange Output in Expect Recordings: How to eliminate, and any reasons why?

So, I have switched to Fedora from Debian recently, and have noticed something odd in the default Fedora BASH shell. If I run autoexpect and record commands, the following sorts of output gets ...
1
vote
2answers
58 views

How to limit parallel jobs

I have a hosts containing file say /tmp/hostlist which requires username & password to login and I am using expect command to login hosts and execute command and come out like below in my bash ...
1
vote
1answer
16 views

Expect exiting, not responding to text sent

I have an expect script that is exiting, instead of processing text that is sent and installing files. I'm trying to figure out why it's not installing files, i.e. not implementing what would be done ...
0
votes
1answer
21 views

Problem with 'string match' and variable

I've been searching for hours and trying multiple things. This is the expect code snippet which works. foreach line [split $expect_out(buffer) \r\n] { if {[string match {*word*} $...
0
votes
0answers
19 views

Using “expect” command to run an interactive program fails

I am trying to solve my question that I've asked here using expect script instead of file redirection. Unfortunately, this solution doesn't work as well (the same behaviour as described in the ...
-1
votes
1answer
50 views

Remote Automation Tools in Linux

Suppose one has a computing environment, in linux, which is static and persistent. I have one-way ssh connections, and the infrastructure is trusted -- it is mine. There exist a variety of branded &...
0
votes
0answers
27 views

sed error on expect script

I am trying to use a simple sed command inside with a expect script spawn sed -n '/0032ff00/,/clogoff/p' /tmp/file.tmp > /tmp/file.tmp1 I get an error: sed: -e expression #1, char 1: unknown ...
1
vote
0answers
19 views

In bash `expect` script autogeneratedd with `autoexpect`, there is a `^G` - what does it signify?

In bash expect script autogen'd with autoexpect,I am invoking line completion with a [TAB] in a situation where line completion offers no completions nor changes the input line. The script excerpt ...
0
votes
0answers
24 views

expect script execute and then detach from child process

I am using expect script to switch to sudo user and then run some custom commands. I am using zsh + Tilix terminal. #!/usr/bin/expect set timeout 60 spawn sudo su expect ": " sleep .5 send &...
0
votes
3answers
102 views

How can I use regex to match the contents which is end with “$” by using expect?

I want to perform some commands to remote server by using expect. But when I use .*\$$ it always cannot match the remote prompt to send the commands. The following it my script: #!/bin/ksh while read -...
0
votes
1answer
57 views

Expect script hanging

I'm trying to use expect to automate my login process in ovpn but due to some mistake it is not going well. My script: #!/usr/bin/expect -f set timeout -1 spawn openvpn --config ./bin/openvpn-lib/...
0
votes
0answers
70 views

Run an os.popen command requiring pseudo terminal from python in bash script

I have a python script which uses size = os.popen('stty size', 'r').read().split() to get the terminal window size so I can print text nicely. My problem arises when I have to run this python script ...
1
vote
2answers
40 views

Change shells in a script function

I'm rocking ZSH as my main shell, but in my .zshrc, I'd like to set up a ssh command with expect so I can ssh into my dev boxes easier when I flash builds (there's literally no security needed it's ...
0
votes
1answer
49 views

Expect dynamic input from bash

Assume the following bash script, questions.sh: #!/bin/bash echo "Hello, who are you?" read REPLY and the following expect script: #!/usr/bin/expect -f spawn ./questions.sh # start our script using ...
0
votes
1answer
43 views

Expect script - sending filename with a variable

I want to create a script so that I copy the newest file from an SFTP server, for that I have created a script that gets the name and put the name in a file. Now I want to create another script to ...
0
votes
0answers
66 views

Bash or Expect Script Manual Automatic Switch

I have updated some more explanations. For example, "any_switch_session_command" is like "/usr/bin/mysql". During "/usr/bin/mysql" session, usually only sql commands and limited bash commands can be ...
0
votes
0answers
37 views

expect command not working

Hi all i am trying to automate using expect. I have a custom utility to login to openstack k8 distro the custom command is as below and it asks for an output kubectl-openstack login --server=...
0
votes
1answer
148 views

Exit out from loop on incorrect password in expect TCL shell script

I have written a code snippet in TCL expect to connect from Server 1 to Server 2 using ssh. Users already may have set passwordless communication between Server 1 and Server 2, or it may ask for a ...
0
votes
1answer
149 views

expect with bash for ssh and ping to remote server

I am developing a code. From server, A ssh session will be established to Server B using spawn, and then from Server B sftp file transfer to Server C. Server A and B can be passwordless or it may ask ...
0
votes
0answers
26 views

using expect to ssh 1 host, apply some commands, exit the device and ssh another device to apply some other commands

Hi I'm trying to use expect for network troubleshooting between two devices. in summary, What I'm trying to achieve is to run a script using expect which enters 2 devices and apply commands. the ...
1
vote
1answer
155 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 ...
0
votes
1answer
138 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
72 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
20 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
20 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
172 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
59 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
64 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
44 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
218 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
30 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
172 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
262 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 ...
1
vote
1answer
1k views

how to send special characters in expect script?

I'm trying to send special characters (password) which contains #?!k;|C . The password is dynamic and cannot be hardcoded in the script, so I'm passing it as variable as shown below $ expect ./...
3
votes
1answer
90 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
432 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
251 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
1k 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
713 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
144 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
83 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 ...
13
votes
4answers
5k 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
168 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
863 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
93 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
322 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
286 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
907 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 ...

1
2 3 4 5 6