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
14 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
0answers
46 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
0answers
18 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.
0
votes
1answer
30 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
1answer
43 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
1answer
38 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
1answer
37 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/...
0
votes
1answer
30 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
3answers
45 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
2answers
49 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 ...
1
vote
2answers
37 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 ...
1
vote
1answer
70 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....
1
vote
0answers
12 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
2answers
38 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. ...
0
votes
1answer
35 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...&...
0
votes
2answers
32 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 ...
0
votes
1answer
45 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 ...
0
votes
0answers
19 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 ...
1
vote
1answer
99 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 ...
1
vote
1answer
122 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 ...
0
votes
1answer
27 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
31 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
27 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
149 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
23 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
27 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
31 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
59 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
31 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
24 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
61 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 &...
1
vote
3answers
734 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
125 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
191 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
41 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
117 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
153 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
100 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
308 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
424 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
255 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
38 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
403 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
529 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
129 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
1answer
21 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
384 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
92 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
73 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 ...
2
votes
2answers
414 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
2 3 4 5 6