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 ...
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
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 ...
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 ...
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?
2
votes
1answer
10k views

Get the output from expect script in a variable

I have an expect script which provides the IP address: #!/bin/expect -f set nodename [lindex $argv 0] spawn virsh console $nodename expect "Escape character is" send "\n" expect "localhost login: " { ...
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:" ...
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 ...
0
votes
1answer
100 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 ...
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=...
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@...
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 ...
1
vote
2answers
1k 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 ...
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....
2
votes
2answers
997 views

How to use `expect` with `zipcloak`?

I create a zip file using zip which includes several files and directories, named test.upd. Now I want to use expect to automatically handle the password encryption. Here are two bash scripts, both do ...
1
vote
1answer
4k views

Expect script to automatically log in, command and show its output

I'm new to scripting and need some help. I am creating an expect script that from a Linux server, that will automatically ssh/log in to our HP StoreOnce Appliance #!/usr/bin/expect -f set password "...
1
vote
1answer
6k views

Capture stdout from ssh session to local machine

I am having to put together a script that will ssh into devices to run a command such as "show running-config" and save the output to a file on my local machine. I have done similar tasks like this ...
1
vote
1answer
5k views

Spawn command not found

I trying to use the spawn command to connect to remote server, execute some commands/script. Here is script: #!/usr/bin/expect for i in `srvctl status database -d PROD | awk -F " " '{print $(NF)}'` ...
1
vote
1answer
434 views

Multiple telnet connection in Expect while loop

I need to get the serial number of some devices listed in a file like this: device_id,ip_address BIOTERIO, 148.000.00.189 N7K-LAN(JAF1651ANDL), 148.000.0.192 LAB_PESADO, 148.000.000.130 ...
1
vote
1answer
503 views

Define input number with expect

I am trying to automate the deployment of a Docker container. Three prompts need to be filled in manually in order to proceed with the deployment. However, they are not to be filled in after each ...
1
vote
1answer
3k views

How to pass parameters to EXPECT using the '-c' option?

I'm using expect inside my bash script by using expect -c, but how do I pass parameters to it? This is what I've tried: FILE="myFile" HOST="myhostname" /usr/bin/expect -c $FILE $HOST ' set ...
0
votes
2answers
898 views

Can I have a (bash) shell with expect running in the background?

I am trying to write an expect script that once started will watch my terminal and run a command every time that it finds a match. Is this even possible with expect? If so, would expect_background ...
0
votes
2answers
341 views

Run a local expect script on a remote server?

So I am trying to basically ssh into a server and run a local expect script on there. I tried to follow something similar to how you'd do a bash command i.e. ssh -A user@remote "bash -s" < ./...