gyn

Win32下的Perl,无用的select,停滞的Tk,结束吧....

华为Q3526E交换机日志导出脚本

package require Expect
set params [open params.txt r]
array set params_arr [list ]
while {![eof $params]} {
 set line [gets $params]
 if [regexp {\[(.*)\](.*)} $line full name value] { set params_arr([string trim $name]) [string trim $value] }
}
close $params
proc q3526e {arr} {
 upvar $arr params
 set buffer [list ]
 if [catch {spawn telnet $params(hostname)} result] { puts $result; exit 1 }
 expect -re {Password} { exp_send "$params(password)\r" } eof { exit 1 }
 expect -re $params(prompt) { exp_send "sup\r" }
 expect -re {Password} { exp_send "$params(password)\r" } eof { exit 1 }
 expect -re $params(prompt) { exp_send "dis log\r" }
 expect -re {More ----} {
  foreach ele [split $expect_out(buffer) "\n"] { lappend buffer $ele }
  exp_send "\r"
  while { [regexp {More ----} $expect_out(buffer)] } {
   expect -re {More ----} {
    foreach ele [split $expect_out(buffer) "\n"] { lappend buffer $ele }
    exp_send "\r"
   } -re "$params(prompt)" {
    foreach ele [split $expect_out(buffer) "\n"] { lappend buffer $ele }
    writelog buffer
    exp_send "\r"
   } eof { exit 1 }
  }
 } -re $params(prompt) {
  foreach ele [split $expect_out(buffer) "\n"] { lappend buffer $ele }
  writelog buffer
  exp_send "\r"
 } eof { exit 1 }
}
proc writelog {buf} {
 upvar $buf buffer
 set curr [clock format [clock seconds] -format %D]
 regexp {([0-9]{2})/([0-9]{2})/([0-9]{2})} $curr match month day year
 set curr "20$year$month$day"
 set log [open [format "%s_%s%s" {c:/3526log} $curr {.txt}] w]
 foreach ele $buffer { puts $log $ele }
 flush $log
 close $log
}
if [catch {eval [string trim $params_arr(act)]} result] {puts $result; exit}

参数文件:
[hostname]网关ip地址
[password]交换机密码
[prompt]<Q3526E>
[act]q3526e params_arr

posted on 2007-01-01 09:46 gyn_tadao 阅读(1186) 评论(0)  编辑 收藏 引用 所属分类: ciscoTclTk

只有注册用户登录后才能发表评论。
<2008年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

常用链接

留言簿(14)

随笔分类(126)

随笔档案(108)

相册

搜索

最新评论

阅读排行榜

评论排行榜