Skip to main content

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
3 answers
46 views

Expect script with Xargs and multiple parameters

I have an expect script that will SSH into a list of routers. The expect script works on a list of routers in a file and is called from a bash script with xargs. Bash : script get-rtr.sh #!/bin/bash /...
Roger McCarrick's user avatar
0 votes
0 answers
69 views

Expect Script TCL ending early

I have the following expect script which works for the most part. I have it connecting to a Cisco switch (eventually a couple hundred) and configuring syslog servers. It checks to make sure that ...
Double's user avatar
  • 53
0 votes
1 answer
55 views

expect - repeatably send "\n\r" before a match expect

I need to netcat a U-Boot and perform NAND script and I use below script spawn netcat -lup 6666 expect "Hit any key to stop autoboot" #autoboot counts down from 3 to 0 and somehow one or ...
thomasyang's user avatar
0 votes
1 answer
41 views

Looking for assistance in expect

I have a bash script that has expect to login to a remote host and run list of commands. It works as expected. It has a flaw, if the user enters the wrong password, the expect script keeps trying the ...
Vra's user avatar
  • 1
1 vote
1 answer
30 views

Automate passing JBOSS installer arguments using Expect Command

I have a JBOSS Installer which when run manually it will prompt for input and below is the sample of the execution is as below [sp@sp baseInstaller]$ ./advStart.sh config Buildfile: /home/sp/jboss/sp/...
sabarish jackson's user avatar
0 votes
1 answer
328 views

expect script sending password before prompt

I have written a small expect script for automatic ssh to remote server. But sometimes my expect script don't work. Actually it sends password before password prompt. Here is my script #!/usr/bin/...
sachu's user avatar
  • 3
0 votes
1 answer
325 views

Correct way to set PS1 prompt over ssh

I am trying to set the PS1 prompt dynamically on the my remote machine. The idea is that when I will do ssh to the remote machine, I will also send the value which will set as a prompt for that remote ...
sachu's user avatar
  • 3
0 votes
1 answer
121 views

Expect stuck after issuing exit command from application

Normally when in interactive mode, when I type in exit, it displays Disconnected from Virtual Machine 'pick0:LINUX' and then returns to the bash shell prompt. With my expect script, it is stuck on ...
supmethods's user avatar
20 votes
1 answer
2k views

Why does unbuffer -p mangle its input?

$ seq 10 | unbuffer -p od -vtc 0000000 1 \n 2 \n 3 \n 4 \n 5 \n 6 \n 7 \n 8 \n Where did 9 and 10 go? $ printf '\r' | unbuffer -p od -An -w1 -vtc \n Why was \r changed to \...
Stéphane Chazelas's user avatar
0 votes
1 answer
438 views

Expect: print a multi-line string all at once using echo

I have the following section in my code expect code: set command "echo $output" spawn bash expect "$ " send "$command\r" expect "$command\r\n" Where output ...
shintuku's user avatar
  • 143
3 votes
0 answers
112 views

Waiting until an application is reading (over a TTY)

I'm writing an expect-style program to interact with a command-line application on Linux. Is there any way that my program can know when the application on the other side of the PTY tries to perform a ...
Subhav's user avatar
  • 31
0 votes
0 answers
479 views

expect script terminating early in Dockerfile

I've got an expect script that I need to run in a Dockerfile. However, the script is terminating after all of the input is sent. What's interesting is that docker build is succeeding. Here's my MRE:...
Daniel Walker's user avatar
1 vote
0 answers
232 views

How do you shut down an expect script in the presence of a complex shell interface?

I am running zsh inside of tmux with prezto, and a basic expect script is exiting improperly: set timeout -1 spawn $env(SHELL) expect -regex ".*" send "echo 'foo'\r" expect -regex ...
Chris's user avatar
  • 1,015
0 votes
1 answer
211 views

How can I use regex to match the contents by using expect?

I am new to expect for using the regular expression. trying to parse below input stream. How it can be parse with regexp. As CNTXID is incremental. "Data" CNTXID = 1 ...
user558421's user avatar
0 votes
1 answer
2k views

adding ansible_python_interpreter to task with expect module fails to get command with become_user

I'm writing a task for CentOS7 inventory in which have to go through prompt dialogues, which I think is best candidate for andible's expect module. - name: setup some command become: yes ...
Sollosa's user avatar
  • 1,969
1 vote
0 answers
232 views

Running expect in systemd unit causes sh syntax error

I am trying to automate the process of connecting to my VPN (SonicWall NetExtender) from my Linux machine by using a systemd unit to call an expect script that supplies the login credentials to the ...
MrDrMcCoy's user avatar
  • 121
1 vote
1 answer
3k 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 ...
VBtheHun's user avatar
1 vote
1 answer
2k 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 [email protected] expect "password:" send "...
sticletele's user avatar
0 votes
1 answer
556 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 ...
onceIHadASoul94's user avatar
2 votes
1 answer
760 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,...
gecko's user avatar
  • 168
0 votes
1 answer
1k 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 "$...
cr001's user avatar
  • 105
1 vote
1 answer
5k 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....
Darkyere's user avatar
0 votes
1 answer
426 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 ...
Nicco's user avatar
  • 55
0 votes
1 answer
486 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, ...
manojs1978's user avatar
0 votes
1 answer
45 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 ...
Chris's user avatar
  • 1,015
1 vote
1 answer
2k 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/...
takumiando's user avatar
0 votes
1 answer
1k 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 ...
Erwann's user avatar
  • 709
0 votes
0 answers
85 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 [email protected]" There are three options that in some case I get them and some not: password for jenkins user: "[sudo] ...
Y.K.'s user avatar
  • 1
0 votes
1 answer
241 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 ...
Mike's user avatar
  • 1
1 vote
2 answers
2k 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 ...
Thisura's user avatar
  • 21
3 votes
1 answer
772 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 ...
henriquehbr's user avatar
0 votes
1 answer
162 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 ...
elbarna's user avatar
  • 13.2k
0 votes
1 answer
84 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 ...
wrkilu's user avatar
  • 1
2 votes
1 answer
658 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.
user2204107's user avatar
0 votes
1 answer
898 views

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

#!/bin/expect -- set vm_num [lindex $argv 0] puts "``````````````````````````````````````````````````````````````" puts "``````````````````````````````````````````````````````````````&...
Asad Javed's user avatar
0 votes
1 answer
948 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&...
user2071089's user avatar
0 votes
0 answers
383 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.
HappyFace's user avatar
  • 1,674
0 votes
1 answer
665 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`...
Nordine Lotfi's user avatar
0 votes
1 answer
4k 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 ...
Nordine Lotfi's user avatar
0 votes
1 answer
222 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):...
Nordine Lotfi's user avatar
0 votes
1 answer
1k 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 [email protected] Enter passphrase for key '/home/me/...
Yves's user avatar
  • 3,381
1 vote
1 answer
2k 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 "...
michelemarcon's user avatar
1 vote
3 answers
2k 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 ...
user457337's user avatar
0 votes
2 answers
2k 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 ...
Suman g's user avatar
  • 109
1 vote
2 answers
539 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 ...
RobbG's user avatar
  • 175
3 votes
1 answer
3k 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 [email protected] The authenticity of host '192.168.1.177 (192.168.1....
Rags's user avatar
  • 33
1 vote
0 answers
215 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, ...
Ibrahim Quraish's user avatar
0 votes
2 answers
280 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. ...
symcbean's user avatar
  • 6,124
0 votes
1 answer
59 views

Failed attempt to expect and send

I'm trying to write a script which git clone. my script: git clone ssh://[email protected]/myproject.git expect "Enter passphrase for key..." send "myPassword" read -p "enter...&...
discCard's user avatar
  • 101
0 votes
2 answers
986 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 ...
bomben's user avatar
  • 529

1
2 3 4 5
7