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
1 answer
16 views

expect script doesn't change password on Solaris

I have this script I run from a Linux machine to change root password on remote Solaris machine reachable by ssh. All seems to be fine, passwd command asks for a password, second password, reply that ...
user avatar
  • 25
0 votes
0 answers
23 views

expect script regular expression not working

In expect script I am trying to capture some text from output Text in output is like ivalue=16ef7baa-0de1-48bf-9e04-d486defbee1c, code: expect -re {^(ivalue)\=(.*)(\,)$} puts "expect_out (0, ...
user avatar
0 votes
0 answers
27 views

How to use single quotes with expect -c "send ..." [migrated]

This works as expected: $ expect -c 'send "one two three"' one two three This however doesn't: $ expect -c "send 'one two three'" usage: send [args] string while executing &...
user avatar
  • 115
0 votes
1 answer
19 views

How does one use Expect with Git interactive CLI w/out resorting to alternative strategies?

Typically, I can use the expect mechanic of expect followed by send. In the case of git's interactive shell, however, this does not work and I must use puts. Is there some trick to restore the normal ...
user avatar
  • 653
0 votes
1 answer
37 views

How to detect the spawn failure in expect command

I wrote this script: #!/bin/sh expect -c " spawn cu -l /dev/ttyUSB0 -s 115200 expect \"foo\" send \"bar\" " echo $? And I run it without /dev/ttyUSB0: $ ls /dev/...
user avatar
0 votes
1 answer
50 views

How to correctly use spawn-expect-send for 'git push'?

The code below is adapted from a solution to "Use Expect in a Bash script to provide a password to an SSH command", so as to pass arguments to git push. I'm not getting any exceptions for ...
user avatar
  • 479
0 votes
0 answers
27 views

Failed to execute command that has three and/or optional answers in sequence?

I have command to execute on Linux: sudo ssh -L 80:localhost:80 -f -N root@10.19.34.11 There are three options that in some case I get them and some not: password for jenkins user: "[sudo] ...
user avatar
  • 1
0 votes
0 answers
40 views

How can I execute command that has three and/or optional answers in sequence?

I have command to execute: "sudo ssh -L 80:localhost:80 -f -N root@10.19.34.11" There are three options that in some case I get them and some not: password for jenkins user: "[sudo] ...
user avatar
  • 1
0 votes
1 answer
37 views

Using expect to write a bash script

I am trying to write a bash script using expect. This bash script will reside on a remote server, to be executed at a later date/time. I am using expect to read in a large data file, perform some ...
user avatar
  • 1
1 vote
2 answers
43 views

How to give file name as current date in expect

I have wrote a script in expect as follows. I want to give date as variable to cd command but when I am giving the date as variable to the command and it add '' commas and therefore it shows a error ...
user avatar
  • 21
3 votes
1 answer
117 views

expect freezes after send

I'm trying to automate a Alpine Linux installation using the following script: expect <<- EOF set timeout -1 spawn setup-disk -e -m sys /dev/sda expect { {WARNING: Erase the ...
user avatar
0 votes
1 answer
36 views

Expect script to power on ilo2, works fine but no exit

This is my script to power on a ILO2 HP server. Works fine(the server power on) but after the power on the ilo console remain open and I can exit from script only using ctrl+c by hand, so the script ...
user avatar
  • 10.9k
0 votes
1 answer
25 views

Sending bunch of commands from txt file in Expect

How to send bunch of commands to Cisco router from txt file like: configure class-map match-any popc_fiberpower004_booster_v4 match access-group ipv4 bng_permit_v4 match access-group ipv6 ...
user avatar
  • 1
1 vote
1 answer
183 views

How to solve the issue that a remote Terminal screen is messed up when using `expect`? (usually after a resizing)

Using expect and password auto-login to remote with ssh, when resizing the window, stty size report old size. Cause commands like vim and less mess up.
user avatar
0 votes
1 answer
216 views

How to run an expect script in parallel rather than sequentially?

#!/bin/expect -- set vm_num [lindex $argv 0] puts "``````````````````````````````````````````````````````````````" puts "``````````````````````````````````````````````````````````````&...
user avatar
0 votes
1 answer
158 views

How to send variable value in send command of expect script

Below is my script proc sendline {line} { send -- "$line\r" } set slot 1 set port 1 for {set x 0} {$x<48} {incr x} { sendline {curl -X POST -d '{"command":"dumpcommand&...
user avatar
0 votes
0 answers
50 views

Linux shell scripting

I want to login to remote server and run multiple commands on the same and exit. As on the remote server I am not having root access, so I am unable to use sshpass. Hence I was trying to use expect ...
user avatar
0 votes
0 answers
40 views

zsh, zpty: How to read the output of a process after it has exited?

Start some command with zpty: zpty -d x ; zpty x 'echo hi' ; sleep 1 How do I read its output now that it has exited? zpty -r x Returns 2, and this behavior seems expected per the manpage.
user avatar
  • 1,287
0 votes
1 answer
147 views

Prevent expect from hanging when running through ssh

Based on another post's answer, i managed to make expect automate vncserver through ssh (optionally on a chroot in this case), like so: ssh user@ip "rm ~/.vnc/passwd" echo -n "`PASS_VNC`...
user avatar
0 votes
1 answer
279 views

Send Ctrl+C to script running through ssh

So i got a script that i run through ssh like so: ssh user@ip <<'EOF' export TERM=xterm #list of commands here EOF Problem is, in certain instance, i need to use Ctrl+C in the terminal, mainly ...
user avatar
0 votes
1 answer
100 views

Automating vncserver with expect not working as expected

I thought of automating the part when i first run vncserver, since it ask for a password (and while i know there a flag to pass a passwd file, i prefer to generate a new one every time i need/want to):...
user avatar
0 votes
1 answer
416 views

expect can't send a passphrase for key

My company offered me a server to do my code job. I have to enter a passphrase every time while login the server. ~$ ssh -o StrictHostKeyChecking=no -p 22 me@x.x.x.x Enter passphrase for key '/home/me/...
user avatar
  • 2,809
0 votes
1 answer
202 views

How to pass variable arguments to expect

I want to pass a variable number of arguments to a expect script: #!/usr/bin/expect set timeout 10 spawn ssh -o "StrictHostKeyChecking no" [lindex $argv 0]@[lindex $argv 2] expect "...
user avatar
1 vote
3 answers
260 views

How to break ping command without waiting for its complete output in expect programming?

I am new to expect programming. In my script i need to run multiple ping commands. I am running below mentioned command: ping $ip rep 100 size 1500 If connection is successful than its all good, but ...
user avatar
0 votes
2 answers
400 views

how to send remote script parameters through expect script

I have a program that creates a dynamic shell script using heredoc "stop_remoteServer_script.sh" template of heredoc below cat<<_STOP > stop_remoteServer_script.sh #!/bin/bash ...
user avatar
  • 109
1 vote
2 answers
125 views

How can I clean up output from expect?

Background: I'm using expect to connect between AMCE.sh and a managed network switch. I can connect to the switch via SSH, log in and issue commands but because of the way the switch manages SSL ...
user avatar
  • 175
1 vote
1 answer
669 views

Expect script is not working on linux machine

when I have to do ssh to one of my machine below is the command and if I type 'yes' it is working and able to login as below. ssh root@192.168.1.177 The authenticity of host '192.168.1.177 (192.168.1....
user avatar
  • 13
1 vote
0 answers
16 views

Catching the query results executed in the remote PostGreSQL server through expect command inside Python script

I want to catch the PostGres query results that gets executed in the remote server (passwordless-ssh) via expect command that is used to supply the password for the given PostGres user. Actually, ...
user avatar
0 votes
2 answers
48 views

Unexpected expect/ssh question

I am seeking to automate ssh password based logins (and a series of actions after logging in). I am aware that the ssh password prompt bypasses STDIN. To that end I put together a quick expect script. ...
user avatar
  • 4,225
0 votes
1 answer
45 views

Failed attempt to expect and send

I'm trying to write a script which git clone. my script: git clone ssh://git@domain.com/myproject.git expect "Enter passphrase for key..." send "myPassword" read -p "enter...&...
user avatar
  • 101
0 votes
2 answers
222 views

When using expect script on boot the output of a list of lines gets shorted. How to increase expect's or the terminal's buffer on boot?

I use the following script that I generated with autoexpect. When used on command line command sudo surfshark-vpn multi gives a list of about 15 lines and then asks for a final input by the user in ...
user avatar
  • 295
0 votes
1 answer
282 views

Exiting an Expect Script

I have this expect script, that will log into a host, run a command, return it's contents and exit. What sort of cleanup/proper exiting needs to happen when I've finished running my command? This ...
user avatar
  • 1,490
0 votes
0 answers
21 views

Is it possible to carry local RSA keys to remote computer (live) and use securely?

Is it possible to store an SSH-id in some sort of session (like expect or ssh) that is running on the local machine, swing into a remote box, and execute a shell command in the remote box as if the ...
user avatar
  • 653
1 vote
1 answer
435 views

redirect each command output to respective log file expect script

set commands { "show phone xxx 11" "show phone yyy 22" "show phone zzz 33" } spawn ssh -o StrictHostKeyChecking=no $UserId@$host sleep 15 #wait for password ...
user avatar
  • 83
1 vote
1 answer
529 views

replace space with underscore in expect script

#!/usr/bin/expect -f set cmd "abc def ghi lkj" set log [ expr echo ${cmd// /_} ] I would like to log variable as ghi_lkj first I wast trying to replace all spaces with underscores and then ...
user avatar
  • 83
0 votes
1 answer
88 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 ...
user avatar
  • 101
0 votes
0 answers
79 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 ...
user avatar
0 votes
1 answer
70 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 ...
user avatar
  • 653
1 vote
3 answers
661 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 ...
user avatar
  • 60
1 vote
1 answer
96 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 ...
user avatar
  • 13
0 votes
1 answer
102 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*} $...
user avatar
0 votes
0 answers
62 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 ...
user avatar
-1 votes
1 answer
75 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 &...
user avatar
  • 653
0 votes
0 answers
52 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 ...
user avatar
  • 1
0 votes
0 answers
52 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 ...
user avatar
1 vote
3 answers
3k 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 -...
user avatar
  • 111
0 votes
1 answer
298 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/...
user avatar
  • 3,474
0 votes
0 answers
281 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 ...
user avatar
1 vote
2 answers
48 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 ...
user avatar
0 votes
1 answer
244 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 ...
user avatar
  • 135

1
2 3 4 5 6