期望脚本regexp不匹配

时间:2013-04-25 22:50:11

标签: regex expect

我有以下期望脚本并尝试匹配返回空行的输出。有人可以帮助regexp吗?

    #!/usr/bin/expect -f
    set force_conservative 1
    set timeout -1
    set U [lindex $argv 0]
    set P [lindex $argv 1]
    set P2 [lindex $argv 2]

    set HOSTLIST [open hosts.list r]
    set HOSTS [split [read $HOSTLIST] "\n"]
    close $HOSTLIST

    set CMDLIST [open cmds.list r]
    set CMDS [split [read $CMDLIST] "\n"]
    close $CMDLIST


    spawn ssh test@test.net

    expect -re ".*password.*" { send "$P2\n" }
    expect -re ".*sshhost.*" {send "telnet $H\n" }
    expect -re ".*sername:.*" { send "$U\n" }
    expect -re ".*ass.*:.*" { send "$P\n" }
    set output [open "outputfile.txt" "a+"]

    expect -re ".*#" { send "$C\n" } # prompt for cisco devices
    expect "$C" ;
    expect -re ".*#" { set raw_outcome $expect_out(buffer) }
    send "\n"
    set outcome ""
    set finaloutcome ""
    regexp {^\s+(.*)} $raw_outcome ignore outcome
    regexp { ^\S+ } $outcome finaloutcome
    puts $output $finaloutcome
    close $output
    expect -re ".*#" { send "exit\n" }

这是一些正常的输出,我只是试图提取第一个单词(ABC,CZE-NW,VRT和TXT)。

    Router-1#sh ip vrf
      Name                             Default RD          Interfaces
      ABC                              65411:111           Lo0
                                                           Lo1
      CZE-NW                           65411:122           Lo5
      VRT                              65411:2227          Lo3527
      TXT                              65411:443            Mu2
    Router-1#

0 个答案:

没有答案