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 and security maintenance. It has a particularly powerful response recognition.

Expect adds many extensions to the Tcl scripting language which simplify scripting interactive applications controlling such hard-to-interact programs as, for example, 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.

Links

Common "gotcha"s

Take careful note of this caveat from the expect(1) man page:

Expect takes a rather liberal view of scoping. In particular, variables read by commands specific to the Expect program will be sought first from the local scope, and if not found, in the global scope. For example, this obviates the need to place "global timeout" in every procedure you write that uses expect. On the other hand, variables written are always in the local scope (unless a "global" command has been issued). The most common problem this causes is when spawn is executed in a procedure. Outside the procedure, spawn_id no longer exists, so the spawned process is no longer accessible simply because of scoping. Add a "global spawn_id" to such a procedure.

Debugging Mode

The expect program has a debugging mode where it prints out exactly what it receives from the spawned programs and what it is looking for. This can be extremely helpful when working out why your scripts are not working! Enable it by passing the -d option on the command line.

2733 questions
0
votes
0 answers

How to automate the download of a SQL file from an AWS server

so I'm currently working with an AWS server project, and I'm trying to figure out how to automate the downloading of this file from AWS. In the MacOS terminal, I can write the individual lines of code that would a) log me in and b) manually grab the…
0
votes
1 answer

I want to download the files having same name from multiple server. but below code is not working properly and slow

Code is working very slow. and output is not as expected, getting only two files in output directory instead of 4. Since i have 4 servers so i should get 4 files. Seems it is creating output file for only first and last…
0
votes
1 answer

Bash+Expect script not working in cron RHEL 7

I have the below script which is working in the terminal but not in crontab.Why it is not running in cron Note:/opt/app/bin/app.exe is having a…
Raju John
  • 23
  • 3
0
votes
1 answer

Using Expect Script to read two columns from text file

I need to write a script on Expect to read a text file that contains two columns. Column one is the site name (dns) and the second is a router interface that will be used as the source-interface when I perform an FTP function from a Cisco router.…
PF75
  • 5
  • 2
0
votes
1 answer

Expect doesn't execute script in screen

I'm trying to execute a script in screen through expect with ssh, but it's never executed. I know this because I do not see a screen session with screen -list. Expects' exit code is 0. If I execute the command through SSH manually, it works. What am…
Bayou
  • 3,293
  • 1
  • 9
  • 22
0
votes
0 answers

how to enter into an infinite loop of expect operations with Tcl?

How can I intentionally enter an infinite loop with the telnet server? (Not literally infinite, but to "cycle" through a sequence with the server.) whenever presented with a menu of "WEATHER UNDERGROUND MAIN MENU" or "CITY FORECAST MENU" I'd to…
Thufir
  • 8,216
  • 28
  • 125
  • 273
0
votes
1 answer

How to toggle Tcl interact and expect for telnet automation?

Similar to but different from autoexpect in that autoexpect will always produce the same output for any given input. Whereas, trying to allow for user input sometimes at least. This works in that it passes control back to the user as…
Thufir
  • 8,216
  • 28
  • 125
  • 273
0
votes
1 answer

Tcl expect error with spawning telnet: invalid command name

How do I send just a "return" to this telnet server: got New York spawn telnet rainmaker.wunderground.com Trying 35.160.169.47... Connected to rainmaker.wunderground.com. Escape character is…
Thufir
  • 8,216
  • 28
  • 125
  • 273
0
votes
1 answer

Timeout Command under Expect not Working as Expected

I'm new to this community as well as programming. I'm currently working on a an simple Expect script that that reads a file with a list of DNS names, SSH into a Cisco router, and does a simple "show ip int brief". This list contains some hosts that…
PF75
  • 5
  • 2
0
votes
2 answers

Can't find package from application written in Tcl

Thanks to the comments, better understand the problem a bit. The variables: thufir@dur:~/tcl/packages$ thufir@dur:~/tcl/packages$ echo 'puts $auto_path' | tclsh /usr/share/tcltk/tcl8.6 /usr/share/tcltk /usr/lib /usr/local/lib/tcltk…
Thufir
  • 8,216
  • 28
  • 125
  • 273
0
votes
2 answers

Expect script fails if directory exists

My expect script that allows me to log into servers with my ssh key fails if the directory it tries to create is already there. When I try to create the directory on the target server the whole script fails with this error: authorized_keys …
bluethundr
  • 1,005
  • 17
  • 68
  • 141
0
votes
1 answer

expect spawn is not executing

hi i have following expect script named a.exp #!/usr/bin/expect spawn cat a.txt where a.txt contains the following single line of string text Hello World next i made it executable by using the following command chmod +x a.exp now, i run it as…
asil2
  • 3
  • 1
  • 3
0
votes
1 answer

Why does strip() fix this pexpect script?

I have an object. This object has a connect() method which spawns a pexpect process. The process that's spawned is a custom serial interface. On launch, this tool prints a menu of serial devices to connect to, like so: libftdi device (0):…
eastydude5
  • 597
  • 2
  • 5
  • 17
0
votes
0 answers

Expect script accepting negative numbers but not positive numbers

I have an expect script that is working if I pass it in a negative number. However, it will now not accept positive numbers. The values I am trying to pass are -12345 and 12345. Here is my script: spawn -noecho $servicecode --enable expect "Do…
jberthia
  • 111
  • 7
0
votes
0 answers

SFTP file transfer between two server and running this script from 3rd server

I have developed a script using TCL expect. The use of the script is - if user runs it from server A, it will check sftp file transfer between server B and server C. Below is my code: #!/usr/bin/expect -f lassign $argv 1 2 spawn ping -c 2 -i 3 -W 1…
newuser
  • 69
  • 3
  • 14
1 2 3
99
100