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
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.
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.)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With