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
3
votes
2answers
4k views

Log the output of Expect command

I have made the below expect script and I need to log the output of that script. SOURCE_FILE=`ls -l *.txt --time-style=+%D | grep ${DT} | grep -v '^d' | awk '{print $NF}' ` if [ -n "${SOURCE_FILE}" ] ...
2
votes
2answers
899 views

Regular expressions with ExpectJ

I've been used the ExpectJ Java library to automate some jobs on a Linux server, however now I need to automate a job that sends a different text response for each execution. Here is the output: Last ...
1
vote
1answer
2k views

Expect script + automated telnet process between three Linux machines

Is it possible to do the following by expect script? I have Linux server that connected to linux_machine1 and linux_machine1 connected to linux_machine2 My Linux server have access only to ...
1
vote
1answer
5k views

How to check whether a given path is a file or directory

I am using the command below in my expect script (in tcl/Tk) for checking whether the entered path is an individual file or directory: set b [exec ./check.sh $file1 | awk -F {=} {{print $1}} ] The ...
1
vote
1answer
27 views

How to spawn expect process with complicated syntax?

In expect it is possible to spawn a process like, spawn /usr/bin/sftp "$uri" /home/user/dest Writing it like this makes things really simple, it will be a one liner. However, I am trying to ...
-1
votes
0answers
18 views

expect(1): display output from process under test for awhile

I want to start a series of commands on a remote and then capture the output for awhile. Then, I want to issue commands to the process under test to shut it down. After running the series of ...
0
votes
2answers
2k views

pexpect fails to match command if greater than 65 characters

Issue with pexpect, python module. Pexpect fails to do expected behavior if the length of the command is greater than 65. #!/usr/bin/python import pexpect sshCmd='ssh root@15.186.22.105' prompt='[...
0
votes
1answer
22 views

'expect' not matching server response string

I'm using a bash script to log into a telnet server and execute a number of commands. It looks like: login_and_run.sh #!/bin/bash unset TELNET_USER_NAME_STRING unset TELNET_PASSWORD_STRING unset ...
1
vote
1answer
7k views

set variable in bash script with EXPECT

I have a bash script which can login to Cisco switch and shut/noshut any port I have defined in it. What I want is that I can add variable, like I can define port number in a command like this: ./...
5
votes
2answers
887 views

When using expect: SSHFS Transport endpoint is not connected

When I run my SSHFS connection script from bash, everything works perfectly. However, when I run the same script using the expect utility, I get the following error when I try to access the folder ...
0
votes
2answers
2k views

Command puts in expect doesn't show the message in the order it should

I have a some scripts to automate a process and I want the message about which step I am in it shows in the command window. A piece of code I have is: puts "** Creation of $VMNAME on $HOST begins... ...
0
votes
2answers
2k views

Expect script connects with ssh but does not run commands

I need to write a script that runs on a PC with Centos 7 and connects to another PC with Centos 7 using ssh, execute a console command, for example "ls -la" and save the output of it to a file to be ...
0
votes
0answers
132 views

how to send special characters in expect script?

I'm trying to send special characters (password) which contains #?!k;|C . these password is dynamic and cannot be hardcoded in script. so I'm passing through variable as below $ expect ./...
1
vote
1answer
59 views

How to write an “expect” script that checks if the supplied password matches one of multiple possible passwords?

I want to change the password on my server. There are four possible passwords that should all be accepted for changing a password on the server. To achieve this I want write an "expect" script ...
3
votes
1answer
40 views

Bash program terminates after a few seconds

I have written a small script to download files from an FTP to external drive that is connected to my Raspberry Pi 3B+. I am using rsync to download my files. Here are the scripts: download.sh: #!/...
2
votes
3answers
3k views

How to automate connecting to multiple network devices, running a command and saving the output to a file?

I have to run a command on around 1000 network devices and save the output to a file. In a file I have a list of all the network device names that have to be connected to using SSH. I then have to run ...
0
votes
1answer
57 views

Cron to Bash Script to Bash Script to Expect Script

I want to execute a series of Expect scripts. The chain of execution goes like this: Cron job starts a bash script, this wrapper starts ~11 bash scripts in Parallel - each of them call an Expect ...
2
votes
1answer
1k views

Expect PECL for PHP 7

I just upgraded to PHP 7.0.3, but there is no support for expect. Does anyone know if is it possible to bypass the installation issue? It says: root@portal:/home# pecl install expect-0.3.3.tgz pecl/...
1
vote
1answer
1k views

`Interact` not working as expected in bash/expect scripting

In order to provision an embedded device (i.e. writing images to flash) a series of very well known commands have to be entered during the boot stage. The algorithm is something like: Capture a ...
1
vote
1answer
1k views

expect: get error status when spawn command fails

The below is the sample of a script which we execute daily for getting info from the server. For the last couple of days, some server data is missing from the output which is captured on the local ...
0
votes
1answer
43 views

Calculating packet loss from ping?

I've got an ESXi VM that does command execution on some 700~ devices on our network. It's using Expect, and due to the age of this equipment they have periods of poor performance. These two don't mix ...
0
votes
2answers
1k views

expect: does “” (spawn_id exp70) match glob pattern

I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match. ...
1
vote
2answers
2k views

expect script for getting output for multiple servers

I am trying to get output of IQN from multiple servers. I am getting the below error. Error output spawn /usr/bin/ssh VM2 | /usr/bin/cat /etc/iscsi/initiatorname.iscsi root@VM2's password: bash: -c: ...
2
votes
1answer
116 views

Remove carriage return (\r) from variable in expect script

Setup Ubuntu 16.04 expect Scripts In the simple script bellow the goal is to simply find the oldest .zip file in a directory on a remote machine using ssh. Then use scp to download this file to the ...
0
votes
0answers
53 views

Unix - Expect Shell - Syntax for using ifcondition on while loop

I have been working on a expect script on AIX OS. The script should pick the server list from input file from while loop and proceed with an if condition to match a specific pattern then proceed. else ...
2
votes
1answer
2k views

Expect script to ssh into a remote host and change its password

So recently I have been working on a small script that will login to a remote unix host and change its password, I've never had much experience with expect so its been an upward learning curve. The ...
1
vote
1answer
1k views

Autoexpect hangs at the end of the script

I have an autoexpect script. I modified it and it works great, however when it finish to run it hangs and I need to do ctrl+C in order to get my terminal [..] 887VA#logout Connection to 10.255.255.1 ...
0
votes
1answer
2k views

How to use EXPECT in a loop foor ssh

Our Linux setup doesn't have keygen configured for password less authentication. Hence I am supposed to use only EXPECT for password less authentication in a shell script. /usr/bin/expect<<...
1
vote
3answers
5k views

How do I spawn a BASH command in expect?

I have an expect script, and want to spawn a BASH command for it to provide input to. When I use the following syntax: spawn /bin/bash docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ...
0
votes
1answer
2k views

Use a script for a telnet session

I have a problem with my script. It seems my password is wrong. #!/usr/bin/expect set ip [lindex $argv 0] spawn telnet $ip set timeout 10 expect "Login:" send "administrator\r" expect "Password:" ...
0
votes
1answer
63 views

Control a bash instance by a script (in a robust way)

I'd like to control some bash programs (local, or ssh) with some (eventually interactive) scripts (say python) in a robust way. I'd like to send commands, get the stdout/stderr of that command at the ...
0
votes
0answers
36 views

How to switch user in the server by su without password through shell script?

I am using cygwin to run my expect command for login into server. Once login i have to switch the user by su command writing password in the shell script which does not prompt for password and ...
5
votes
1answer
432 views

Unix AIX passing variable and arguments to expect and spawn

I am writing a script to scp some files but need to pass file location through the user or another script as an argument #!/usr/bin/expect set FILEPATH1 $1 spawn sh "scp $FILEPATH1 $USER@$HOST:/...
13
votes
4answers
3k views

What happens if I start too many background jobs?

I need to do some work on 700 network devices using an expect script. I can get it done sequentially, but so far the runtime is around 24 hours. This is mostly due to the time it takes to establish a ...
0
votes
1answer
1k views

Counting files on a remote server with ssh and an expect script

Below is my script to take count for files which are present in remote server. But it is not working. #!/usr/bin/expect spawn ssh sduser@172.0.0.2 expect "123" send "123" interact destPath='/...
0
votes
1answer
35 views

Manually enter password into expect and use as variable while scrip is running

I have an expect script that uses interact every time a password is needed. The program that expect is automating asks for the password multiple times. Is there a way to only have to type the ...
1
vote
3answers
8k views

pass parameters to bash script using chef attributes

I have a bash script ( let's say main.sh ) which I need to integrate with chef. Currently we are using "expect" to pass the parameters to main.sh. Now I need to make script in such a way that the ...
0
votes
2answers
1k views

Expect Scripts - Reading from Files and Accepting User Input

How can I write an "Expect" script to: iterate over a list of IP addresses and log in to each to perform commands (like in a BASH for loop). Right now I just copy/pasted the few lines that are my ...
1
vote
2answers
2k views

Cracking root user: Automating logging into root using “su” from nonroot user

I want to write a script that allows me to pass a password to the su command. The reason for this is to automate the process of logging into root from nonroot account. From my basic understanding of ...
2
votes
2answers
2k views

Huge delay in script response when using SFTP with expect

I am using a script to call SFTP service to fetch some logs from the remote server. This works fine in normal scenario but, i have noticed a very long delay of around 30 minutes or more in some of the ...
0
votes
2answers
713 views

Monitoring of disk space on multiple Linux server using expect script

I'm trying to write a script using Expect for monitoring multiple servers; the connections will be through ssh using a password. My basic loop is self failing, I'm not sure whether Expect TCL ...
2
votes
1answer
549 views

Restrict `expect` to stdin/stdout interaction only

I need to accept job files from users, which would essentially consist of console interaction with a process I will be running for them. Naturally, the first idea that came to mind is to use expect ...
2
votes
1answer
398 views

How to make a script “wait” for an operation to finish?

I have two scripts, or maybe better call one a wrapper for the another. Here comes the wrapper: #!/usr/bin/expect set timeout 20 spawn "./installOracleDatabase.sh" expect "replace Disk1/upgrade/...
0
votes
1answer
2k views

Expect Rsync with Double quotes

Below is my code: #!/usr/bin/expect -f set timeout -1 spawn rsync -arvz -e 'ssh -p 1690' --protect-args --progress /home/pappu/ 'backup@xx.xx.xx.xx:/volume1/56 - Backup Server/pappu' expect "password:...
0
votes
3answers
842 views

Sending shell script command keystrokes to a remote shell

Is it possible to make the script run when it shifts from normal mode to the interactive mode. #/bash/bin sudo gatttool -b 80:EA:CA:00:00:03 -I # All these commands are typed in interactive mode ...
29
votes
10answers
198k views

Shell Script for logging into a ssh server

I tried writing a shell script which can do automatic login into a ssh server using password which is mentioned in the script. I have written the following code: set timeout 30 /usr/bin/ssh -p 8484 ...
0
votes
0answers
38 views

File Movement between server's that have the same case-insensitive filename

We have a table contains the file name's which are considered as inbound feed every week and one of the file name is as below File_name : FEB_MERC_DATA_??????.txt Sample inbound file which we got in ...
2
votes
1answer
239 views

Expect script multiple Q/A

I have the following expect script: #!/usr/bin/expect set timeout 20 set cmd "/path/vpntool --server 1.2.3.4:443 --vpnuser user" set password [lindex $argv 0] eval spawn $cmd expect "VPN:" ...
0
votes
1answer
121 views

Commands leaking characters to bash

While building a small expect script I noticed that, after executing the script, some characters were automatically on the input of bash. I have seen that on other programs before, but here I have ...
0
votes
2answers
216 views

Tcl script with multiple spawn expect and send

I am trying to automate the installation of certificate(s):q! in jboss server. i wrote this rudimentary script: #!/usr/bin/expect set Temp_Dir "/tmp/install" set jboss_sec "/opt/jboss/security" set ...