Questions tagged [expect]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
0 answers
132 views

unable to send response in expect command

I'm running below command and I'm also sending response using send but its not taking any input. kindly tell me where I'm missing? #!/usr/bin/expect -f set server_ip "<server?" spawn ...
3 votes
2 answers
5k views

expect script to support two expected characters

I want to run sshd restart on Linux and Solaris machines via expect. ( my expect runs in my ksh script ) I created an expect script. When expect sees a prompt "#" it runs sshd restart. I ...
0 votes
1 answer
2k views

expect usage in bash script or bash command in expect script

I have a script below that works except for the expect portion: #!/bin/bash # invdir=/home/john/inventory for file in $invdir/$1 do if [ -z $1 ] || [ -z $2 ] then echo "You must enter a ...
5 votes
3 answers
4k views

How to keep script from swallowing all of stdin?

I have a script that reads from a pipe in a loop and runs an expect script and a normal shell script in the loop. Both scripts run ssh to another server to grab a piece of data. For example: cat /...
0 votes
1 answer
2k views

screen, expect and scripted detached interaction

Trying to write a bash script which will open a screen, start a python application, and interact with the python interaction as required when it is first started. If not possible in screen, I would ...
2 votes
1 answer
3k views

run several bash scripts with expect code and leave them running

I have a bunch of several bash scripts that will perform some actions that require user input, therefore I'm using expect with it. However, I need one to keep running. But if I use expect, the expect ...
0 votes
1 answer
66 views

Script Need to send mail if condition dont match [closed]

looking for your advise.. i have expect script which execute perfectly and save output to a file, filename is 'fileout'.. output from fileout shows like below.. NAME ...
0 votes
2 answers
1k views

shell scripting with expect and a complex command line: no such file or directory

I'm trying to make this work #!/usr/bin/expect spawn "(psql blabla \"blabla sql;\" &> /dev/null) && (pg_restore -d xx my_file.sql &> /dev/null)" expect "Password for user ...
1 vote
1 answer
2k views

expect script works fine standalone not from bash script

I am running a expect script,which login to a server check if iptables running and return the log file of the status. There is a hostfile also given with server list and password, expect is being ...
0 votes
1 answer
486 views

Continue statement doesn't work as it should - bash

For the context, i have an infrastructure of multiple machines using ssh. We connect via ssh as root on the machines without password thank's to the authorized_keys file on each mchine. We are adding ...
1 vote
1 answer
447 views

Using expect to automate Alpine Linux installation in FreeBSD in Bhyve

I am attempting to automate installation of Alpine Linux in vm-bhyve under FreeBSD and expect dies shortly after the boot menu times out and launches the Alpine Linux installation. #!/usr/bin/env ...
16 votes
3 answers
76k views

Expect timeout, in Bash scripting

How do I add timeout for "expect" in the following script? I want to set it as 120 seconds. #!/bin/bash HOST="localhost" USER="myuname" PASS="mypassword" VAR=$(expect -c " spawn ssh $USER@$HOST ...
0 votes
1 answer
642 views

Restart services on multiple remote servers securely

I need to write a script so that my colleagues and myself can restart different services on multiple servers. We all connect to the servers with LDAP so i'd like my script to connect our LDAP users to ...
4 votes
1 answer
7k views

using ansible --ask-become-pass in a variable

I would need to use my --ask-become-pass password in an expect script. Is there any way to use the password entered when starting ansible_playbook in a variable? Pseudo-code: # ansible-playbook --...
0 votes
0 answers
183 views

on expect: need to spawn a python script that fetches a string and send it back

The first script is basically an external lib that I don't want to tamper with. I already tried the following: set timeout 100 spawn python long-running-script-with-prompt.py expect "Type the 6 ...
0 votes
0 answers
126 views

Bash to expect script to add user

Need help Required to convert below bash script in expect script. #Script to Add User tail /etc/passwd | cut -d: -f1 read -p 'Please Enter The Username To Add: ' name echo "$name" > /tmp/...
1 vote
1 answer
1k views

Merging Expect script and Bash script

This is my expect script for login into a remote server.where i ask user to put password. #!/usr/bin/expect -f #Grabbing Password to be used in script further stty -echo send_user -- "Enter the ...
0 votes
1 answer
169 views

Trim and allign an output of command in expect script

{ echo ' ' ;echo ' IP : ' ;ip route get 8.8.8.8 | cut -d' ' -f7,8 | tr -d 'src' ;echo ' ' ;dmidecode -t bios | grep -iw 'Version' ;echo ' ' ;} the output of above command mentioned is: IP : 10.0.0.1 ...
0 votes
1 answer
1k views

how to use ping in expect script

Need assistance while i want to ping server if got reply then proceed with script and if no reply go again to previous step where we fetch IP from hosts.txt #Setting up Variables set timeout 5 ...
0 votes
0 answers
325 views

Expect Script: First ping the IP stored in hosts.txt file and if got response of ping run script

for below code i want to check if the IP is up via ping and if ip is up run below code eles check next ip from hosts.txt Edit 2: FYI ill be running script from windows machine Edit 3:I managed to ...
9 votes
2 answers
39k views

Expect script error send: Spawn id exp4 not open while executing

I'm trying to run this script but having different errors when modified. Here is the code and the output. Please help. Updates at the end of the post with debug info #!/bin/bash (( $# != 1 )...
7 votes
1 answer
9k views

How to get installed unbuffer on centos?

$ unbuffer -bash: unbuffer: command not found Centos 7.x How to install it by using yum? yum install unbuffer doesn't work.
0 votes
3 answers
16k views

Can I use expect with SCP to bypass the password prompt?

I am trying to transfer some files using SCP in a shell script, but I am being prompted for my password on the remote machine. Can I use expect with scp to enter the password so I don't have to type ...
0 votes
0 answers
235 views

I would like to automate the ssh login to an AIX server that hs

I would like to automate the login to an AIX server. I dont have a way to set up ssh keys im on mac so i cant install ssh pass so my only option left would be expect. #!/usr/bin/expect -f set ...
2 votes
3 answers
5k views

password check in bash script calling on expect

Background: I have to copy a file from one server, to over 100 servers in a test environment. once the file is copied, it requires to have the permissions on the file changed/verified. These are all ...
0 votes
1 answer
1k views

catch bash script output from expect, expect hangs

I currently use expect to pass password to rsync to copy files across unix servers test.sh ./expect.sh $password rsync -azvr $username@$host:$file ./$dir expect.sh #!/usr/bin/expect -f ...
7 votes
2 answers
4k views

How to detect timeouts in an expect script

Consider an expect script that spawns a command and waits for a sequence of events. We use this to test software. I'm trying to always get a failure return value from the script when there is a ...
-1 votes
1 answer
764 views

kpcli bash script to automate entries

I am trying to create a bash script which uses kpcli in order to automate entries into a kdbx file. While searching over here I found out that you could use expect and send, however this does not ...
1 vote
2 answers
12k views

#!/usr/bin/expect not working

This is probably an easy question, however have a simple expect script that I've add the executable bit to that seems to be ignoring the #!/usr/bin/expect interpreter line. Further more, it also ...
1 vote
0 answers
203 views

expect, mpd5 and dynamic config loading

I have a FreeBSD server that's connected to WAN using PPPoE. Iva esuccessfully set ip the L2TP and PPTP VPN ontop of this PPPoE WAN connection. The problem is that L2TP needs to call 'set lt2p self ` ...
1 vote
0 answers
753 views

Ansible expect does not pass response to kibana keystore

Ansible expect is not passing ansible variable on first pass. If I make changes and re run the script adding an additional response question then the script seems to work but if I just want to set ...
1 vote
1 answer
877 views

Expect Scripting: Is there a way to default back to a previous spawn_id?

After I scp a file using spawn, the spawn_id, exp8, closes out. gets eof. so, any other commands I run after that, I get this message: an not find channel named "exp8". So I'm assuming that once a ...
1 vote
1 answer
3k views

expect: how to use expect scripts from within a bash subroutine

I want to write a login script in expect. But I want this to be reused in different other scripts. I want to make all the login commands part of a bash subroutine. ie instead of expect_login.sh #!/...
5 votes
3 answers
55k views

Expect script too fast: add a sleep between each line read from a file

I am trying to automate switch commands. It's almost all good, but when the expect script reads each line from the file containing my switch commands (listed line by line), the switch seems to stop ...
0 votes
4 answers
10k views

How to use expect in Bash script and ssh-copy-id

From a bash script: source ./expect.sh I am including a expect code: #!/bin/bash /usr/bin/expect <<EOL spawn ssh-copy-id -i /home/user/.ssh/id_rsa.pub 111.111.111 expect '*?assword*' send '...
1 vote
2 answers
3k views

Linux Expect Script terminates too early

I have an expect script that I have written that at the end calls scp to copy a large file from server A to server B. The issue I have (which is the same using rsync and not scp) is that the expect ...
0 votes
1 answer
354 views

Forwarding access to mysql via ssh tunnel with the help of expect

I have this command that creates a working ssh tunnel for access to MySQL server: ssh -f test@remotehost -L 127.0.0.1:3306:mysqlhost:3306 -N Here, remotehost is accessible only via jump host which ...
0 votes
1 answer
2k views

How to use SFTP BatchMode inside EXPECT[Shell Script]

I have set of series SFTP commands which needs to run inside expect. But when i run the below script due to some reasons am not getting any output. Please correct me if am wrong any where inside the ...
1 vote
1 answer
4k views

expect script not working with bash script

I want a script that ssh to remote server and then run a script which is at my local machine and then store the output on my local machine Expect script for ssh to remote server: #!/usr/bin/expect -...
1 vote
1 answer
499 views

Expect doesn't recognize output on Cisco router

I'm writing a script with expect to configure cisco routers automatically via ssh. A part of this script is to copy an image into flash if it doesn't exist: For this expect sends a copy and waits for ...
-1 votes
3 answers
2k views

Linux + how to run the ssh-keygen interactive from bash script [closed]

Please advice how to generate the file id_rsa.pub without answering the questions from "ssh-keygen -t rsa" my target is to run the ssh-keygen from bash script from postgress USER, and it must run ...
0 votes
0 answers
219 views

Expect is prompting password twice while spawn

spawn ssh -q [email protected] Password: Password: Expect is expecting null before I sent the password. Debug info expect: does "" (spawn_id exp6) match glob pattern "yes/no"? no "Password: "? no ...
0 votes
1 answer
8k views

Ansible expect not passing response

I am trying to use Ansible with the expect module to join a linux server to a active directory with sssd. code from the task: - name: join domain expect: command: /bin/bash -c "/usr/sbin/realm ...
2 votes
1 answer
4k views

Ansible "expect" module with sudo?

I want to run an installer script with Ansible. The installer script prompts for a number of responses and requires to be run with root privileges. Here is the essence of my Ansible task: - expect: ...
2 votes
1 answer
2k views

How to use wget in an Expect script?

I first download a file to /root/TRY1/: #!/usr/bin/expect cd /root/TRY1/ exec wget --http-user $user --http-password $password $url Then I want to extract the file: cd /root/TRY1/ exec bash -c "tar ...
0 votes
1 answer
743 views

SSH to ESXi server with Expect immediately closes

I am writing a VM deployment tool that needed to start VMs on an ESXi server. To do this I am using Perl's Expect module to spawn an ssh client to connect to the server and use vim-cmd to manage the ...
0 votes
1 answer
58 views

Same script, same OS, same installation, failing

So I'm working with RANCID to monitor some switches and I'm using clogin now to test some modifications. I'm working in two different computers but both of them from the office. Althought they are ...
0 votes
1 answer
3k views

Expect Scripting Issue Reading From File

I am trying to change the password for a user on a bunch of linux based routers pulling IPs from a list. The iplist.txt is just a list of ips (one per line). This is the code I am trying to use: #...
5 votes
1 answer
5k views

Sending content of a file in Expect

How Can I send the content of a file in Expect? Do I have to use cat command in a way? if yes how? lets say my file is called 1.txt. example: expect "Enter command to send:" {send "???? \r"} ???? -->...
1 vote
1 answer
55 views

SFTP script gets different destination response when run from different directories

I'm baffled by an SFTP shell script and any help would be greatly appreciated. I wrote an sftp script to connect to and upload ACH information to a banking site. The script uses 'expect' to wait for ...