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

Creating a branch in expect, using an IF statement

I am writing an expect script to deal with a plethora of prompts. The bash script that I am working with can follow one of two sequences: prompt1 -> prompt2 -> prompt3 prompt1 -> prompt3 ...
0 votes
1 answer
50 views

Shell script with EXPECT and PUT to SFTP server

I'm working on a shell script and I'm trying to send a backup file to a sftp server : remotepath=/backup/ expect -c " spawn sftp user@172.11.23.4 expect "password:" send "...
0 votes
1 answer
30 views

bash script for activeDirectory join; facing issues using expect to bypass password entry

Will preface here stating that this is poor practice but I have been requested anyway to store the svc-account credential within the script which will live in vRA for VM template.. not my choice, but ...
2 votes
1 answer
25 views

Expect script does continue after putting a value

I wrote the following expect script: #!/usr/bin/expect -f set timeout 10 spawn zypper in --no-recommends pdns expect { -re {^.* Solution (\d): (?:break pdns)} { set solution "$expect_out(1,...
  • 138
0 votes
1 answer
143 views

Expect: how to properly close a while loop in bash using infinite expect spawn?

I have the following script: #!/usr/bin/expect set timeout 20 set cmd [lrange $argv 1 end] set password [lindex $argv 0] eval spawn $cmd while {1} { expect "id_rsa" send "$...
  • 105
0 votes
1 answer
323 views

Using expect in bash to execute a command with a password request

I have worked for a while on making a BASH script to go through two lists and creating a command out of it. In the end it should execute the command and synchronize my ZFS server and ZFS backup server....
0 votes
1 answer
121 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 ...
  • 35
0 votes
1 answer
150 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, ...
0 votes
1 answer
24 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 ...
  • 715
0 votes
1 answer
345 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/...
0 votes
1 answer
204 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 ...
  • 501
0 votes
0 answers
30 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] ...
  • 1
0 votes
0 answers
45 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] ...
  • 1
0 votes
1 answer
70 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 ...
  • 1
1 vote
2 answers
286 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 ...
  • 21
3 votes
1 answer
226 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 ...
0 votes
1 answer
61 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 ...
  • 11.2k
0 votes
1 answer
31 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 ...
  • 1
1 vote
1 answer
255 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.
0 votes
1 answer
375 views

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

#!/bin/expect -- set vm_num [lindex $argv 0] puts "``````````````````````````````````````````````````````````````" puts "``````````````````````````````````````````````````````````````&...
0 votes
1 answer
395 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&...
0 votes
0 answers
51 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 ...
0 votes
0 answers
64 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.
  • 1,335
0 votes
1 answer
241 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`...
0 votes
1 answer
803 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 ...
0 votes
1 answer
113 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):...
0 votes
1 answer
680 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/...
  • 2,891
0 votes
1 answer
444 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 "...
1 vote
3 answers
442 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 ...
0 votes
2 answers
636 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 ...
  • 109
1 vote
2 answers
201 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 ...
  • 175
1 vote
1 answer
1k 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....
  • 13
1 vote
0 answers
20 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, ...
0 votes
2 answers
81 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. ...
  • 4,374
0 votes
1 answer
46 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...&...
  • 101
0 votes
2 answers
413 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 ...
  • 355
0 votes
1 answer
474 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 ...
  • 1,520
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 ...
  • 715
1 vote
1 answer
582 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 ...
  • 93
1 vote
1 answer
764 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 ...
  • 93
0 votes
1 answer
141 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 ...
  • 101
0 votes
0 answers
150 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
1 answer
88 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 ...
  • 715
1 vote
3 answers
934 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 ...
  • 60
1 vote
1 answer
177 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 ...
  • 13
0 votes
1 answer
203 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
0 answers
129 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
1 answer
91 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 &...
  • 715
0 votes
0 answers
63 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
0 votes
0 answers
66 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 ...

1
2 3 4 5 6