Questions tagged [expect]

79 questions
14
votes
3 answers

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 expect \"password:\" send \"$PASS\r\" expect…
Bijo
  • 209
  • 1
  • 3
  • 6
8
votes
1 answer

Ansible ssh as user and execute has root (expect like)

I have to administer an important number of hosts where there is only one user able to access from SSH (let's call him foo) and then have to login as root to execute privilegied commands. Foo user doesn't have any kind of sudo privileges so I'm…
Arka
  • 173
  • 1
  • 2
  • 8
7
votes
1 answer

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.
Kirby
  • 889
  • 1
  • 9
  • 16
7
votes
2 answers

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 )) && { echo >&2 "Usage: $0 \"[COMMAND]\""; exit 1;…
GoldFlake129
  • 73
  • 1
  • 1
  • 5
7
votes
2 answers

expect script + expect miss the send string + delay issue

I write the active.ksh script (based on expect) in order to login automatically to some Solaris machine and execute the hostname command (login to virtual IP in order to verify which hostname is the active machine - I have two cluster solaris…
Eytan
  • 601
  • 6
  • 13
  • 26
6
votes
3 answers

SU and Run Command Using Expect

I want to su to another user, using expect, and then run a graphical program as that user. I am using kcalc to test with: #!/usr/bin/expect set timeout 20 spawn su dummy expect "Password:" send "PASS\r"; send "kcalc\r" I also tried eliminating the…
Sarah Cain
  • 61
  • 1
  • 2
5
votes
3 answers

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 after about 10 or 15 commands, i think the buffer…
2legit2quit
  • 171
  • 1
  • 2
  • 10
5
votes
2 answers

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 /tmp/file | while read a b c d do s=`expect-script…
Justin
  • 51
  • 1
  • 2
5
votes
1 answer

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"} ???? --> content of the file 1.txt.
user121560
  • 51
  • 1
  • 2
5
votes
2 answers

expect + how to identify if expect break because time out?

The target of the following simple expect script is to get the hostname name on the remote machine Sometimes expect script fail to perform ssh to $IP_ADDRESS ( because remote machine not active , etc ) so in this case the expect script will break…
Eytan
  • 601
  • 6
  • 13
  • 26
5
votes
1 answer

How to print the name of an expect script?

In bash, I can do something like this: echo "The name of this script is $0" Is there a way to do something similar in expect?
Runcible
  • 2,955
  • 3
  • 22
  • 15
4
votes
2 answers

help with expect script, run cat on remote comp and get output of it to the variable

I have a bash+expect script which has to connect via ssh to the remote comp, read the file there, find specific line with the "hostname" (like "hostname aaaa1111") and store this hostname into the variable to be used after while. How can i get the…
lugger1
  • 43
  • 1
  • 1
  • 4
4
votes
1 answer

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 --become --ask-become-pass -i testing master.yml BECOME…
TobiM
  • 131
  • 1
  • 7
3
votes
2 answers

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 timeout. spawn some-command set timeout 10 expect…
3
votes
2 answers

expect script to support two expected characters

I want to run sshd restart on Linux and Solaris machine via expect ( my expect run in my ksh script ) I create expect script so when expect see the prompt "#" then he run sshd restart but the problem is that I run this expect also on solars and the…
yael
  • 2,363
  • 4
  • 28
  • 41
1
2 3 4 5 6