免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1948 | 回复: 3
打印 上一主题 下一主题

使用perl的net::telnet模块遇到一个问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-08-08 10:02 |只看该作者 |倒序浏览
我使用perl的net::telnet模块进行登陆extreme的summit24三层交换机时,第二个命令 show ports 6 info 不能正常执行,如果把第一个命令show fdb和第二个命令show ports 6 info对调一下,那show fdb则不能执行,看来是程序的后半段有问题,不知谁能赐教在下,毕人不胜感激。
   
源程序如下:
!/usr/local/bin/perl
use Net::Telnet;
$t= new Net::Telnet (Timeout =>; 10);
$t->;open('x.x.x.x');
  $t->;waitfor(Match=>;'/login:/');
  $t->;print("xxx";
  $t->;waitfor(Match=>;'/password:.*$/');
  $t->;print("xxx";
  $t->;waitfor(Match=>;'/#/');
  $t->;print("";
  $t->;print("show fdb 00:07:95:52:cd:ee";
  open(EP,">;/home2/zlj/public_html/yingyong/zhanghao/file4";
  @list=$t->;cmd(String=>;"show fdb  00:e0:4c:85:76:b7",Prompt=>;'/#/');
do
     {
           ($prematch, $match) = $t->;waitfor('/Press <SPACE>; to continue or <Q>; to quit#/');
           if ($match =~/Press <SPACE>; to continue or <Q>; to quit:/)
                     {
                    #    print  $prematch ;
                    #    print $match;
                        $t->;print("";
                     }
                        print  $prematch ;
           print  EP $prematch;
     } while ($match =~ /Press <SPACE>; to continue or <Q>; to quit:/);
   close(EP);
   open(FP,"/home2/zlj/public_html/yingyong/zhanghao/file4";
   $_=<FP>;;
   $_=<FP>;;
   $_=<FP>;;
   $_=<FP>;;
   @jieruport=split(/\s+/,$_);
   print "$jieruport[6]\n";
   close(FP);
open(EP,">;/home2/zlj/public_html/yingyong/zhanghao/file5";
  $t->;waitfor(Match=>;'/#/');
   $t->;print("show ports 6 info";

   @list=$t->;cmd("show ports 6 info";

   print @list;

do
     {
           #($prematch, $match) = $t->;waitfor('/Press <SPACE>; to continue or <Q>; to quit#/');
           ($prematch, $match) = $t->;waitfor('/#/');
           if ($match =~/Press <SPACE>; to continue or <Q>; to quit:/)
                     {
              #          print EP $prematch ;
                        $t->;print("\n");
                     }
         print EP $prematch;
           print  $match;
     } while ($match =~ /Press <SPACE>; to continue or <Q>; to quit:/);
    close(EP);
     
$t->;close;
;

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-08-08 13:22 |只看该作者

使用perl的net::telnet模块遇到一个问题

$t->;waitfor(Match=>;'/#/');
看起來這行多餘了...前面
@list=$t->;cmd(String=>;"show fdb  00:e0:4c:85:76:b7",Prompt=>;'/#/');
這邊他就已經回到 # _ 的等待畫面...
你再wait 當然就會超時了....

论坛徽章:
0
3 [报告]
发表于 2005-08-08 14:02 |只看该作者

使用perl的net::telnet模块遇到一个问题

我做了好几个有关net::telnet的程序,感觉它不是很稳定,不知有否同感?

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
4 [报告]
发表于 2005-08-09 20:08 |只看该作者

使用perl的net::telnet模块遇到一个问题

我都用expect写....然後用system("xxx.exp";执行....
这样我比较知道在干嘛....不过expect语法也蛮奇怪的..but 挺好用的..
给你叁考...
perl里面也有个Expect.pm....也还行...但是我习惯expect了...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP