Questions tagged [expect]

Expect is a utility based on TCL. It's primary use is for building automation into interactive environments such as telnet or ssh based terminal environments.

It provides the ability to enter commands on a command line and interpret the output.

Expect adds many extensions to the Tcl scripting language which simplify scripting interactive applications controlling such hard-to-interact programs such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. Expect/tcl can run a GUI interface or run from the command line. Since Tcl is a full featured programming language, Expect can easily interact with databases, webservers, etc. with intuitive, powerful, and easy-to-anticipate processing.

Expect is in the public domain. There is full support for Linux and Windows.

Overview and history website: http://www.nist.gov/el/msid/expect.cfm
Support and download website: http://expect.sourceforge.net/
FAQs website: http://expect.sourceforge.net/FAQ.html

63 questions
15
votes
1 answer

What is the meaning of the "spawn" command in Linux (Centos6)

I need to know how to set up a cron job that automatically connects to a remote server, then changes to a directory and downloads all the files in that directory to local. I think I have to use SFTP but I saw the following command using "spawn" in…
7
votes
1 answer

Can Expect make sure a certain log does not appear?

Expect scripting is great for writing tests that are basically "make sure that running this command causes these logs to be printed". Expect lets you skip past the irrelevant output and look for specific lines in the logs. Is there a way to make…
6
votes
1 answer

Which characters require escaping in expect strings?

I know that hard brackets [, ] require triple backslash escaping when used inside expect "..." strings, so I use expect "blah blah \\\[herp derp\\\]" to accurately convey these characters to the expect I/O checker, but what other characters also…
mcandre
  • 3,098
5
votes
3 answers

How to by-pass user interactions in a script?

I am trying to automate the installation of a program through a shell script. There are a few steps which require user interaction from the command line (confirmation, yes/no, etc.). What is the best way to by-pass it? I know that one possibility is…
Vignesh
  • 53
4
votes
3 answers

Automating an ssh connection with crontab

I've been struggling to crontab automate a git push process with ssh, and it's proving tricky to setup a key with the ssh agent. Starting with a basic script to test the agent: # set paths (all examples) source /etc/profile export…
geotheory
  • 1,099
2
votes
1 answer

expect + how to verify if dir exists and if not how to create it

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 directory , then need to create this directory and add…
maihabunash
  • 489
  • 2
  • 6
  • 16
2
votes
1 answer

expect command in ubuntu

I've searched all over SuperUser, but couldn't get the solution. Here is a script that am using for ssh using expect. I'm using ubuntu and I've installed expect using aptitude install expect. #!/usr/bin/expect -f spawn ssh user@server expect…
2
votes
2 answers

couldn't execute "mysql": no such file or directory, using autoexpect

I have the following file: exp.exp #!/usr/bin/expect db_host='localhost' db_name='webui_dev' db_user='root' db_pass='rootpass' new_db_name='db_2011' expect <
2
votes
2 answers

Bash/expect script to log in via ssh and port knocking. SSH Keys not possible

My login server is behind a firewall that uses port knocking to allow entry. The login-flow is Enter in port knocking command. This requires my external IP to be entered. When prompted, enter in my port-knocking password. Enter in ssh command Enter…
2
votes
2 answers

Installation of Expect on Windows 7 64-bit fails with "not found in the archives"

Downloaded ActiveTcl from http://www.activestate.com/activetcl/downloads/ Installed ActiveTcl at c:/Tcl/ Go to Bin directory in command prompt (Start > Run > cmd > cd c:\Tcl\bin) To install Expect, I executed the command teacup install Expect I…
Master James
2
votes
1 answer

expect -timeout vs. "set timeout" in expect: Different behavior

I was testing a expect script and found two different behaviors when using set timeout vs. expect -timeout. Here is a simple example response.sh: #!/usr/bin/bash sleep 2 echo hello test1.sh: #!/usr/bin/expect spawn ./response.sh set timeout…
2
votes
1 answer

How do I get my expect statement to not output the stdout of the first command?

What I'm trying to do is execute an ssh command that prints out the /etc/shadow file. Obviously that file requires root or sudo permission, and I don't have root creds, therefore I have to use sudo. Here is the command I've worked out: expect -c…
2
votes
1 answer

How can I set up nautilus to use a ssh connection established by an expect script?

In order to automate a ssh connection, I wrote a script using expect, which works just fine. However, I would like to use this script in the nautilus connect to server function. My idea was to include this expect script somehow into the .ssh/config…
1
vote
1 answer

Expect script for telnet communication with DLink router

I am trying to connect to my router through telnet using this script: #!/usr/bin/expect -f set timeout 20 # router user name set name "admin" # router password set pass "admin" # router IP address set routerip "192.168.1.1" # Read command as…
shivams
  • 1,804
1
vote
1 answer

sending GREP command fails

I'm new to expect scripting and trying to get below script to work. The script logs in to a server and reads a config file ($val in the script) for the values of "cps" and then presents a total value, but got stuck when sending a long "grep" command…
Dalman
  • 11
1
2 3 4 5