+ -
当前位置:首页 → 问答吧 → 【求助】perl expect 登陆问题

【求助】perl expect 登陆问题

时间:2010-08-11

来源:互联网

有时候匹配得过去,有时候匹配不过去得,请大侠帮忙
问题在这一块Are you sure you want to continue connecting (yes/no)?


#!/usr/bin/perl
  use Expect;

$ENV{TERM} = "vt100";

       my @server_ip=('10.8.4.136');
       my $ip=@_;
     # my $exp = Expect->new;


foreach $ip(@server_ip){
     my $timeout = 2;
     my $pass="aic1234";
   

    $exp = Expect->spawn("ssh -l yanzy $ip";
    $exp->log_file("output.log";

   $exp->exp_internal(1);
   $exp->log_stdout(1);

    $exp->expect(2,[
                 qr/password:/i,
         sub {
               my $exp = shift ;
               $exp->send("$pass\n";
               exp_continue;
             }

                 ],

                [
                    'connecting (yes/no)?',
                    sub {
                      my $exp = shift ;
                      $exp->send("yes\n";

                        }
                ]

              );


[bankdplyop@cnsz040545 unix_deploy]$ auto2
Starting EXPECT pattern matching...
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561
        Expect::expect('Expect=GLOB(0xa64baa0)', 2, 'ARRAY(0xa64c230)', 'ARRAY(0xa64c280)') called at ./auto2 line 39
spawn id(3): list of patterns:
  #1: -re `(?i-xsm:password'
  #2: -re `connecting (yes/no)?'


spawn id(3): Does `'
match:
  pattern #1: -re `(?i-xsm:password'? No.
  pattern #2: -re `connecting (yes/no)?'? No.

The authenticity of host '10.8.4.136 (10.8.4.136)' can't be established.
RSA key fingerprint is 72:05:2f:55:58:ee:6f:e8:fa:36:69:cc:24:ec:d1:24.
Are you sure you want to continue connecting (yes/no)?
spawn id(3): Does `The authenticity of host \'10.8.4.136 (10.8.4.136)\' can\'t be established.\r\nRSA key fingerprint is 72:05:2f:55:58:ee:6f:e8:fa:36:69:cc:24:ec:d1:24.\r\nAre you sure you want to continue connecting (yes/no)? '
match:
  pattern #1: -re `(?i-xsm:password'? No.
  pattern #2: -re `connecting (yes/no)?'? YES!!
    Before match string: `The authenticity of host \'10.8.4.136 (10.8.4.136)\' can\'t be established.\r\nRSA key fingerprint is 72:05:2f:55:58:ee:6f:e8:fa:36:69:cc:24:ec:d1:24.\r\nAre you sure you want to continue '
    Match string: `connecting '
    After match string: `(yes/no)? '
    Matchlist: (`')
Calling hook CODE(0xa57a060)...
Sending 'yes\n' to spawn id(3)
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1267
        Expect::print('Expect=GLOB(0xa64baa0)', 'yes\x{a}') called at ./auto2 line 36
        main::__ANON__('Expect=GLOB(0xa64baa0)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 760
        Expect::_multi_expect(2, 'undef', 'ARRAY(0xa64c4d0)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 565
        Expect::expect('Expect=GLOB(0xa64baa0)', 2, 'ARRAY(0xa64c230)', 'ARRAY(0xa64c280)') called at ./auto2 line 39
Sending '\003' to spawn id(3)
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1267
        Expect::print('Expect=GLOB(0xa64baa0)', '\x{3}') called at ./auto2 line 42
Starting EXPECT pattern matching...
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561
        Expect::expect('Expect=GLOB(0xa64baa0)', 2) called at ./auto2 line 43
spawn id(3): list of patterns:


spawn id(3): Does `(yes/no)? '
match:

Starting EXPECT pattern matching...
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561
        Expect::expect('Expect=GLOB(0xa64baa0)', 1, '$passwd') called at ./auto2 line 45
spawn id(3): list of patterns:
  #1: -ex `$passwd'


spawn id(3): Does `'
match:
  pattern #1: -ex `$passwd'? No.

Starting EXPECT pattern matching...
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561
        Expect::expect('Expect=GLOB(0xa64baa0)', 2) called at ./auto2 line 47
spawn id(3): list of patterns:


spawn id(3): Does `'
match:

fcntl returned undef during exp_init of Expect=GLOB(0xa64baa0), 错误的文件描述符

作者: yanzy   发布时间: 2010-08-11

为什么 第二个'connecting (yes/no)? 匹配没有exp_continue? 而且匹配connecting (yes/no)也不能这么写吧,看是不是需要转义

作者: demil   发布时间: 2010-08-11

热门下载

更多