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