【求助】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), 错误的文件描述符
问题在这一块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="

$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

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

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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28