免费注册 查看新帖 |

Chinaunix

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

用expect和vmware交互时发生的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-09-24 16:01 |只看该作者 |倒序浏览
本帖最后由 sunkun_99 于 2012-09-24 16:04 编辑

用expect模块去一个vmware系统某个目录/proc/scsi/qla2xxx/下有两个文件0和1, 想通过expect模块来获取文件名,然后发送cat命令读出文件内容。
取文件没有问题, 但是发送命令时文件名却被加上莫名期奇妙的字符,不知是何原因?请教各位大侠!

程序运行结果如下:
  1. [root@ilaus1-dev test]# a.pl
  2. FileName:    0
  3. ls /proc/scsi/qla2xxx/;0m0m
  4. 0  1
  5. -sh: 0m0m: not found
  6. ~ #
  7. *********************************
  8. FileName:    1
  9. ls /proc/scsi/qla2xxx/;0m1m
  10. 0  1
  11. -sh: 0m1m: not found
  12. ~ #
  13. *********************************
  14. [root@ilaus1-dev test]#
复制代码
可以看到文件名0 和 1 没有任何问题,但是发送命令却变成了0m0m和0m1m。
程序源码如下:
  1. #! /usr/bin/perl
  2. use strict;
  3. use Expect;
  4. use Data::Dumper;

  5. my $conn = Expect->new();
  6. $conn->log_stdout(0);
  7. $conn->spawn("ssh 192.168.1.103") or die "Can't spawn!";
  8. my $rc = $conn->expect(3,'-re', qr/#/);
  9. my @temp;
  10. if($rc) {
  11.     $conn->send("ls /proc/scsi/qla2xxx\n");
  12.         my $out;
  13.         while($conn->expect(3,'-re', qr/[\s\S]+/)) {
  14.             $out .= $conn->match();
  15.         }
  16.         @temp = split /\n+/, $out;
  17.         @temp = grep !/ls|#/, @temp;
  18. }
  19. foreach (@temp) {
  20.         my @t = split /\s+/, $_;
  21.         foreach (@t) {
  22.             print "FileName:    ",$_,"\n";
  23.            
  24.             #这行发送命令将$_中的0或者1加上了其他字符,不知是和原因???
  25.             $conn->send("ls /proc/scsi/qla2xxx/".$_."\n");
  26.             
  27.             my $out;
  28.             while($conn->expect(3,'-re', qr/[\s\S]+/)) {
  29.                 $out .= $conn->match();
  30.             }
  31.         print $out,"\n*********************************\n";
  32.         }
  33. }
  34. $conn->close() or die "Can't close!\n";
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP