如何在使用Expect'send'命令的同时将输出存储在变量中 [英] How to store output in a variable while using expect 'send' command

查看:969
本文介绍了如何在使用Expect'send'命令的同时将输出存储在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谢谢.

但是需要帐户和密码.因此,我必须先发送它们,然后发送ovs-vsctl命令.

But the account and password are needed. So I must send them and then send ovs-vsctl command.

脚本是这样的:

spawn telnet@ip 

expect -re "*login*" {
       send "root"
}

expect -re "password*" {
       send "****"
}

send "ovs-vsctl *******"

我想存储此命令send "ovs-vsctl ****"的输出,但是很多时候我都得到了命令"send"password"的一些输出,如何获得send "ovs-vsctl****"的输出.命令send "ovs-vsctl ***的输出是两个字符串,每个字符串占用一行.

I want to store the output of this command send "ovs-vsctl ****", but many times I got some output of the command "send "password"", how can I get the output of send "ovs-vsctl****". The output of the command send "ovs-vsctl *** are two string and each string occupies one line.

谢谢.

推荐答案

也许:

log_user 0                   ;# turn off the usual output
spawn telnet@ip 
expect -re "*login*"
send "root\r"
expect -re "password*"
send "****\r"
send "ovs-vsctl *******"
expect eof
puts $expect_out(buffer)     ;# print the results of the command

这篇关于如何在使用Expect'send'命令的同时将输出存储在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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