Tcl 如何格式化从expect脚本生成的程序的输出

Tcl 如何格式化从expect脚本生成的程序的输出,tcl,expect,Tcl,Expect,我正在使用tcl和expect为radius服务器编写负载测试脚本。 我正在从远程服务器上的脚本调用radius服务器内置的radclient。 脚本执行以下操作: 使用远程服务器IP -将ssh生成到远程服务器 -调用radclient -使用radclient命令执行负载测试 -需要将输出结果(如示例输出所示)收集到变量中 -从上一步的输出或变量中提取每秒身份验证作为每秒事务(TPS) 需要关于最后两个步骤的帮助: radclient的示例输出: *--> timetest 20 10

我正在使用tcl和expect为radius服务器编写负载测试脚本。 我正在从远程服务器上的脚本调用radius服务器内置的radclient。 脚本执行以下操作:

使用远程服务器IP -将ssh生成到远程服务器 -调用radclient -使用radclient命令执行负载测试 -需要将输出结果(如示例输出所示)收集到变量中 -从上一步的输出或变量中提取每秒身份验证作为每秒事务(TPS)

需要关于最后两个步骤的帮助:

radclient的示例输出:

*--> timetest 20 10 2 1 1
Cycles: 10, Repetitions: 2, Requests per Cycle: 10
Starting User Number: 1, Increment: 1
Current Repetition Number=1
Skipping Accounting On Request
Total Requests=100, Total Responses=100, Total Accepts=0 Total Not Accepts=100
   1: Sending 100 requests and getting 100 responses took 449ms, or 0.00 authentications/sec
Current Repetition Number=2
Skipping Accounting On Request
Total Requests=100, Total Responses=100, Total Accepts=0 Total Not Accepts=100
   2: Sending 100 requests and getting 100 responses took 471ms, or 0.00 authentications/sec
预期产出:

TPS achieved = 0

您可以使用如下内容:

expect -re {([\d.]+) authentications/sec}
set authPerSec $expect_out(1,string)
puts "TPS achieved = $authPerSec"
然而,这并不是说提取的信息是正确的信息。例如,当针对测试数据运行时,它很可能会不稳定,因为由于所有重复,有两个地方每秒进行
身份验证
;我们一点也不解释!更复杂的模式可能提取更多的信息等等

expect {
    -re {([\d.]+) authentications/sec} {
        set authPerSec $expect_out(1,string)
        puts "TPS achieved #[incr count] = $authPerSec"
        exp_continue
    }
    "bash$" {
        # System prompt means stop expecting; tune for what you've got...
    }
}
做正确的事情有时会很复杂