【问题标题】:How to format output from a program spawned from a expect script如何格式化从期望脚本生成的程序的输出
【发布时间】:2014-04-15 11:31:32
【问题描述】:

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

获取远程服务器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

【问题讨论】:

    标签: tcl expect


    【解决方案1】:

    你可能会使用这样的东西:

    expect -re {([\d.]+) authentications/sec}
    set authPerSec $expect_out(1,string)
    puts "TPS achieved = $authPerSec"
    

    但是,这并不是说提取的信息就是正确的信息。例如,当针对您的测试数据运行时,它很可能会因为所有重复而出现authentications/sec 的两个地方;我们根本不考虑这一点!更复杂的模式可能会提取更多信息等等。

    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...
        }
    }
    

    有时做正确的事可能很复杂……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      相关资源
      最近更新 更多