Perl Expect - 如何控制目标机器上的超时
我是 Perl 的新手。我正在使用 perl Expect 模块生成到远程系统。使用发送模块依次执行一组命令(例如 $exp->send("my command as string gone here\n")。问题是我执行的命令需要一些时间来处理。之前所有命令完成后,远程计算机都超时,我回到主机提示符,您能帮我解决这个问题吗?
我还有一个问题,它在执行后返回 2 个值。 远程计算机上打印两个值)。我想捕获这两个值并使用发送模块作为参数传递给下一个命令,
请帮助我解决这个问题
。
我正在 关于expect模块的一些东西。有一个undef选项可以与expect一起使用,例如$exp->expect(undef)。这将无限期地等待并让所有命令完成其处理。将控制权返回给主机还有另一种选择,即使用expect 和eof,它将等待直到遇到eof,然后返回主机。虽然不知道具体如何使用它。我发现的一个优雅的解决方案是使用 ssh 在远程计算机上运行命令,而不是使用 Expect,在这种情况下我们不必处理超时。 :)
I am a newbie to perl. I am using perl expect module to spawn to a remote system. Execute a set of commands there one after another using the send module(like $exp->send("my command as string goes here\n"). The problem is the commands that I execute take some time for processing . And before all the command finish the remote machine gets timed out and I come back to my host machine prompt. Can you please help me how to handle this.?
I have one more question. I have a command which returns 2 values after execution(say I am doing a print for 2 values on remote machine). I want to capture these 2 values and pass as argument to the next command using send module. How do I do this.
Pls help me with this problem.
Thanks.
I just found out something about the expect module. There is an undef option that can be used with expect like $exp->expect(undef). This will wait indefinitely and lets all commands finish their processing. But the problem is that, it does not return back the control to the host machine. There is one more option of using expect with eof which will wait until it encounters an eof and then returns to the host machine. Although no idea precisely how to use it. An elegant solution that I found is to use ssh to run commands on remote machine rather than using expect in which case we do not have to deal with timeouts. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚发现了一些关于expect模块的信息。有一个 undef 选项可以与 Expect 一起使用,例如 $exp->expect(undef)。这将无限期地等待并让所有命令完成其处理。但问题是,它不会将控制权返回给主机。还有一种将expect 与eof 一起使用的选项,它将等待直到遇到eof,然后返回到主机。虽然不知道具体如何使用它。我发现的一个优雅的解决方案是使用 ssh 在远程计算机上运行命令,而不是使用 Expect,在这种情况下我们不必处理超时。 :)
I just found out something about the expect module. There is an undef option that can be used with expect like $exp->expect(undef). This will wait indefinitely and lets all commands finish their processing. But the problem is that, it does not return back the control to the host machine. There is one more option of using expect with eof which will wait until it encounters an eof and then returns to the host machine. Although no idea precisely how to use it. An elegant solution that I found is to use ssh to run commands on remote machine rather than using expect in which case we do not have to deal with timeouts. :)