Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for a process to complete using tcl-expect

Tags:

shell

expect

tcl

I am writing a script using expect in which I have to rlogin to some host & after that I need to send some commands. Now I want to exit to that host and relogin again to some other host and send some commands. But the run of my script is not waiting for first host to complete its jobs and exit instead it sends other commands in between the previous process. How can I achieve this using expect please guide?

Sample code is as follow :

#!/usr/local/bin/expect -f

spawn rlogin host1
expect "%"
send "source xyz.csh\r"
send "exit\r"
expect "%"

spawn rlogin host2
some set of commands
like image 445
XYZ_Linux Avatar asked May 15 '13 10:05

XYZ_Linux


People also ask

What is expect in Tcl?

Expect is an extension to the Tcl scripting language written by Don Libes. The program automates interactions with programs that expose a text terminal interface. Expect, originally written in 1990 for the Unix platform, has since become available for Microsoft Windows and other systems.

What is Exp_continue in Expect?

The command exp_continue allows expect itself to continue executing rather than returning as it normally would. By default exp_continue resets the timeout timer. The -continue_timer flag prevents timer from being restarted. (See expect for more information.)


1 Answers

you're forgetting to "hit enter". After sending exit, the way to wait for the process to end os expect eof:

send "source xyz.csh\r"
expect "%"
send "exit\r"
expect eof
like image 160
glenn jackman Avatar answered Sep 21 '22 18:09

glenn jackman