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
56 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
126 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
47 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
18 votes
1 answer
1k 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
141 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
2 votes
0 answers
63 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
  • 21
0 votes
0 answers
275 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
134 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
  • 961
0 votes
1 answer
123 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
911 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,919
1 vote
0 answers
178 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
2k 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
365 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
585 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
  • 138
0 votes
1 answer
928 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
4k 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
359 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
424 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
33 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
  • 961
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
865 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
  • 645
0 votes
0 answers
66 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
178 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
661 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
144 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
  • 12.6k
0 votes
1 answer
48 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
556 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
777 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
855 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
267 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,613
0 votes
1 answer
531 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
3k 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
194 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,261
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
1k 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
1k 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
419 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
2k 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
194 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
211 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
  • 5,462
0 votes
1 answer
57 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
862 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
  • 479
2 votes
2 answers
1k 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 ...
Kahn's user avatar
  • 1,702
0 votes
0 answers
23 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 ...
Chris's user avatar
  • 961
1 vote
1 answer
1k 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 ...
bhr's user avatar
  • 103
1 vote
1 answer
1k 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 ...
bhr's user avatar
  • 103
0 votes
1 answer
254 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 ...
Max's user avatar
  • 101

1
2 3 4 5
7