如何使用tcl-expect等待过程完成 [英] How to wait for a process to complete using tcl-expect

查看:635
本文介绍了如何使用tcl-expect等待过程完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用期望编写脚本,在该脚本中我必须重新登录某些主机&之后,我需要发送一些命令.现在,我要退出该主机,然后再次重新登录到其他主机,然后发送一些命令.但是我的脚本运行不是在等待第一个主机完成其工作并退出,而是在上一个进程之间发送其他命令. 我如何使用Expect请指导?

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?

示例代码如下:

#!/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

推荐答案

能否详细说明静态脚本在上一个过程之间发送其余命令."

Can you elaborate on "still script sending rest of the commands in between the previous process. "

我尝试了这个,并且奏效了.

I tried this and it worked.

spawn ssh host1
expect ":"
send pwd1
expect "%"
send "echo hi\r"
expect "%"
send "exit\r"
expect eof
spawn ssh host2    
expect ":"
send pwd2

这篇关于如何使用tcl-expect等待过程完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆