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
29
votes
10answers
192k 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 ...
14
votes
3answers
68k views

spawn - command not found!

I am using Mac OS X 10.9.4, following is my script to copy files from local machine to different host #!/bin/bash #!/usr/bin/expect echo "I will fail if you give junk values!!" echo " " echo "Enter ...
14
votes
3answers
51k views

bash script error stty: standard input: Inappropriate ioctl for device

I'm using here-documents in a bash script to automate installation and setup where a password is required many times. I enter the password once and the script passes it to the various commands. In ...
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 ...
11
votes
1answer
7k views

Can I build a Docker container from Dockerfile in an interactive way with allocation of some pseudo TTY?

I build container from below Dockerfile: FROM ubuntu:14.04 ... RUN apt-get update && apt-get install -y vim #RUN ssh-keygen -f /root/.ssh/id_rsa -N strongpass123$%^ RUN ssh-keygen -f /root/....
8
votes
2answers
7k views

Removing non printable characters from expect logs?

How can I either strip the following character sequences from my files? ^[[64;8H, ^[[?25h, ^[[1;64r etc or avoid having expect add them in the first place? Background: I'm using a collection of ...
7
votes
1answer
13k views

bash and expect in the same script?

I'm trying to code an script that takes IP addresses from a .csv file and telnet the device to catch "show version" command output. So far I have coded this: #!/bin/bash #!/usr/bin/expect -f FILE1=...
7
votes
1answer
4k views

Why is expect's interact command not working?

I am trying to automate gdb with expect. My script will start gdb, do some initialisation, and then pass the control to the user. Expect's interact command seems like the perfect tool for the job. ...
6
votes
2answers
12k views

Create a directory if it doesn't exist in TCL

I write expect script that login to remote machine and run there some scripts But I need also to verify the following Verify if directory /var/cti/adm/APP exists. If APP not exists under adm ...
6
votes
2answers
4k views

sudo askpass: ask from other tty

Context I want to setup rsync backups of my server, so I run the following command rsync -r -e ssh --rsync-path="sudo rsync" rsyncuser@example.com:/ /backup/ Ideally, that command would ask my ...
6
votes
2answers
19k views

Cross compiling expect for ARM

I have downloaded expect5.4 . I'm trying to cross compile it for ARM(PandaBoard) running stripped down version of linux. In the initial setup of configuring , I try Shell$ ./configure --host=ARM ...
5
votes
1answer
238 views

expectk in Debian 9

I am reading the book "Why programs fail" from Andreas Zeller. It has exercises that requires using the Android automation tool (not to be confused with Google's OS). I could download it from the ...
5
votes
2answers
5k views

scp command behaves differently when used with expect utility

expect -c 'spawn scp -C -o CompressionLevel=9 ~/partFiles/* abc@10.200.4.15:/export/home/abc/; sleep 10; expect password; send "secretPassword\n";interact' throws - ~/partFiles/*: No such file or ...
5
votes
1answer
26k views

error handling in expect?

I am just improving my question because I have achieved so far up to this: set username [lindex $argv 0] set password [lindex $argv 1] set hostname [lindex $argv 2] if {[llength $argv] == 0} { ...
5
votes
1answer
332 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:/...
5
votes
2answers
861 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 ...
4
votes
1answer
791 views

How to send keystrokes before interactive shell to automate Linux serial port login with GNU screen?

I often have to login into Linux devboards with known fixed usernames and password via the serial port. The normal commands are: screen /dev/ttyS0 115200 and then inside screen the session looks ...
4
votes
1answer
8k views

Calling an expect script in a loop of a bash scrip

I am trying to loop a list of sites through an expect script. The loop will take my list and read it line by line, change directories to the folder of the site name, then pass the site name to an ...
4
votes
2answers
2k views

encfs with expect access denied

If I execute script #!/usr/bin/expect set pass [lindex $argv 0] spawn encfs -v {CRIPT_DIR} {MNT_DIR} -o nonempty expect "*EncFS Password:*" send "$pass\r" expect eof expect script output: zz@...
4
votes
1answer
428 views

Pass variable to spawn [duplicate]

I want to pass server name which is listed in a file (servers_list) as variable to spawn command which is in another script (user_create_script). Purpose of this script is to create user(david) in ...
3
votes
3answers
23k views

How to auto type password for SCP or SFTP to automate it?

I have script where I put scp command to backup file to other server. But when it runs it asking to type password. Is there way to automate this? I am using CentOS 5.6. I have seen few guides they use ...
3
votes
3answers
798 views

How to send part of the data through the pipe/file and later interactively?

I have a command I want to run, let's call it program. It is an interactive program similar to bash or python REPL. I want to start this program with some predefined input. I tried program << "...
3
votes
3answers
6k views

Pass the background flag (&) through expect and ssh

My command line/bash fu is extremely weak, but I'm trying to hone my abilities. Hopefully someone can help. I wrote a super simple expect script so that I can SSH in to a headless box we're using at ...
3
votes
4answers
4k views

passing passwords to a script

I want to scp a file to a remote host, and from there, run a command on the file, and exit the remote session. If I write a usual script, call scp and then ssh, I am prompted to enter two passwords. ...
3
votes
1answer
322 views

Expect to automate yes answer to CLI

When I run the command ambari-server upgrade from a bash script, in the middle of the upgrade we get the question have made a backup of the Ambari Server database [y/n] (y)? so we want to automate ...
3
votes
2answers
2k views

How can I get `expect` to ignore $ (dollar sign) in a password?

I'm running an expect script and the password has a $ character. The shell looks for the following characters to expand into something and spits out no such variable. Is there any way around this?
3
votes
2answers
24k views

script to automate scp in network

I have a network full of Linux machines. In this network, I have a user as user1 with the password as password in all the machines. I have the following script to put files in the home directory of ...
3
votes
2answers
8k views

SSH + Sudo + Expect in Bash script: Run command with sudo in remote machine

I am trying to automate the deploy of some .deb packages with an script. I want to execute sudo dpkg -i $myDeb.deb in a list of remote machines I can access with ssh. I've tried to automate the ...
3
votes
2answers
3k views

How do I expect a newline in expect script?

Consider this interactive script: #!/usr/bin/env bash set -eu while true; do read -p '> ' if [ "$REPLY" == quit ]; then break fi echo "'$REPLY'" done Now I want expect to ...
3
votes
1answer
766 views

Why does a gdb client fail to talk to its gdb server when started by this “expect” script?

I'm building a continuous integration environment for a firmware codebase, programming an ARM Cortex M0 using a Segger JLink device and running tests on the target using gdb and Segger's RTT tool. I ...
3
votes
1answer
854 views

How to use `expect` with `zipcloak` II?

This question is a followup on this question, as I figured out the solution I presented in the previous question does not work anymore. It worked sometime, but now expect does not work as expected. ...
3
votes
1answer
38 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: #!/...
3
votes
1answer
408 views

Expect to scp directory does not work when run from post commit

I am trying to implement a post-commit hook on svn which will scp some files from the svn machine to some other backup machine after each commit. I have written the script with expect as follows ...
3
votes
3answers
8k views

Using expect to send Ctrl+D to a telnet connection

I want to use expect file for connecting to telnet session automatically, the flow is: when we connect to some IP & port, it will show escape character is ] after that we have to give Ctrl+D I ...
3
votes
2answers
19k views

sftp a file using shell script

I have read through several threads (which have been helpful) and I'm still getting an error when trying to sftp a file (client wants it to be sftp'ed) Here is the script: #!/bin/bash HOST=XX.XX....
3
votes
1answer
3k views

Using expect script to automate password checking for a multitude of routers

The task at hand is to check the passwords of a multitude of routers and change it in case any password is still set to default that is, (for .eg) Login: ABC , Password: ABC. I've written an expect ...
3
votes
1answer
3k views

how to get exit status from command in expect script

Below is an shell script I have written to automate entering the password for the vpnc command. The expect works fine and vpnc activated automatically after password entered, but I need to get the ...
3
votes
2answers
10k views

grep output of expect script

I'm trying to run some expect language, and grep/parse the output all in one script. I want to grep the output of and look for "error" (I should note that standard linux commands like awk, sed, grep, ...
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}" ] ...
3
votes
0answers
228 views

unbuffer/expect swallows the rcode when its child is signaled

unbuffer is able to pass along the return code of a process under normal circumstance, but if the process you are unbuffering is killed, for instance with a segfault, I see $? as 0 while I expect 139. ...
2
votes
3answers
756 views

Cat in expect script adds new line to end of string

I have the following in an expect script spawn cat version expect -re 5.*.* set VERSION $expect_out(0,string) spawn rpm --addsign dist/foo-$VERSION-1.i686.rpm The cat command is getting the version ...
2
votes
3answers
4k views

Convert password with special characters for use with expect script

I have an expect script that connects to an SFTP site and uploads some files. The ID and password are contained in local text files. The expect script reads those files in as a variable and then ...
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 ...
2
votes
2answers
1k views

Automate creation of an at job using expect

I am trying to write a script that will take time and process-name and pass them to at to schedule the job. I cannot send the EOT. #! /usr/bin/expect # Usage: setupkill.exp time process. #...
2
votes
1answer
213 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:" ...
2
votes
3answers
472 views

How to escape a character in a heredoc bash script

I have a bash script which read an input file and using a heredoc to ssh to a server using expect, but am having issue escaping some special character in the input file. Here is what I have.. I have ...
2
votes
1answer
340 views

Expect script is returning errors when spawning bash script. Why? [duplicate]

I am testing out Expect to get a basic template working. I have created a demo bash script which asks a few questions and outputs the inputs to a file. When I execute the .exp file directly or ...
2
votes
2answers
7k views

spawn command issue in Expect Script

I am using KALI Linux and have some trouble with an expect script. I don't know why the spawn command doesn't perform any action, it just echos out the same text #!/usr/bin/expect -f spawn apt-get ...
2
votes
2answers
6k views

Expect script: How to handle two processes?

I am using Expect to automate VoIP calls for quality measurements. My script is calling another VoIP client for a given amount of times. Before the calls should be handled, tcpdump should sniff all ...
2
votes
1answer
254 views

Deadlock with yes command

I have a script called setup.sh: . install.sh && . tolinux.sh && . startn.sh && . startm.sh This is install.sh: yes | sudo apt-get update yes | sudo apt-get install default-...