预计脚本记录未完成 [英] Expect Scripting Logging not finishing

查看:71
本文介绍了预计脚本记录未完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Expect脚本,该脚本将配置命令从文件提供给路由器.我将进程记录到文件中,但是希望在配置文件结束之前停止写日志.例如,如果配置文件具有

I have an expect script that supplies configuration commands from a file to a router. I log the process to a file however expect stops writing to the log before the end of the configuration file. For instance if the config file has


q
r
s
t
u
v
w
x
y
z
eof

日志将具有直到u的所有交互,但其余的交互不在日志中,但似乎该过程一直完成到z.通常,文件比较结束似乎无效,因此我尝试了以下操作.

The log will have all the interaction up to u but the rest is not in the log but it appears the process finished all the way to z. The usual end of file comparison does not seem to work so I tried the following.

    set ok 0;
    while { $ok == 0 } {
      set line [ gets $config ];


       expect  { 
            "#" { send -s "$line\r"; }
            -re "\[.]" { send -s "$line\r"; }
        }
         if { $line == "eof" } {
           set ok 1;
        } else { }

   }
   close $config

将ok设置为1并保留while语句,但脚本在此之前停止记录.

It gets to setting ok to 1 and leaves the while statement but the script stops logging before that.

推荐答案

完成时间是否太长?我想问的原因可能是由于不匹配您的Expect语句中的任何一个选项而导致超时(第一个选项与'#'提示符匹配...第二个选项应该匹配什么?),在这种情况下,在期望时间之后在每次通过时,代码仍将遍历配置文件中的所有行,并最终到达eof并将ok设置为1.

Is it taking too long to complete? Reason I ask is maybe it is timing out due to not matching either option in your expect statement (first option matches a '#' prompt... what is the second option supposed to match?), and in that case, after expect times out in each pass, code would still sweep through all lines in your config file, and eventually reach eof and set ok to 1.

这就是我要做的:

  • 在脚本开头的某个位置包含expect_internal 1,以了解正在发生的事情
  • 在设置和发送语句后删除分号... afaik期望不使用那些(我认为会抱怨!)
  • 在您的Expect语句中添加timeout选项(第3个选项),并且可能在到达时打印相应的内容
  • include expect_internal 1 somewhere at the beginning of your script, so as to get a clue of what is going on
  • remove the semicolons after your set and send statements... afaik expect does not use those (I thought it would have complained!)
  • add a timeout option (a 3rd option) to your expect statement, and maybe print something accordingly if it gets there

我假设您说的"q r s t u v w x y eof"命令列表不是单行代码,而是每行一个命令,对吗?

I assume the list of commands you say is "q r s t u v w x y z eof" is not a one-liner but one command per line, correct?

此外,我假设您在脚本顶部的某个位置有set config [open "/path/to/filename.txt"],而您没有在其中的代码段中显示它吗?

Also, I'm assuming you have a set config [open "/path/to/filename.txt"] somewhere at the top of your script, and you are not showing it in your snippet there?

如果需要帮助,可以随意发布添加exp_internal 1后得到的任何内容.

Feel free to post whatever you get after adding exp_internal 1 if you need help with that.

这篇关于预计脚本记录未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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