Chinaunix首页 | 论坛 | 博客
  • 博客访问: 175666
  • 博文数量: 159
  • 博客积分: 7007
  • 博客等级: 准将
  • 技术积分: 1750
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-17 15:05
文章分类

全部博文(159)

文章存档

2010年(39)

2009年(106)

2008年(14)

我的朋友

分类:

2010-06-30 10:10:50

#!/usr/bin/perl
use Expect;
$Expect::Log_Stdout = 1;
 
$ENV{TERM} = "vt100";
my $host = "192.168.16.33";
my $pass = "123456";
my $exp = Expect->new;
$exp = Expect->spawn("ssh -l root $host -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no");
$exp->log_file("output.log", "w");
$exp->expect(2,[
                    qr/password:/i,
                    sub {
                            my $self = shift ;
                            $self->send("$pass\n");
                            exp_continue;
 
                        }
                ],
                [
                    'connecting (yes/no)',  
                    sub {
                            my $self = shift ;
                            $self->send("yes\n");
                         }
                ]
            );
#$exp->interact() if ($exp->expect(undef,'#'));
$exp->send("uptime\n") if ($exp->expect(undef,'#'));
$exp->send("exit\n") if ($exp->expect(undef,'#'));
$exp->log_file(undef);

阅读(385) | 评论(0) | 转发(0) |
0

上一篇:perl模块安装

下一篇:shell使用总结

给主人留下些什么吧!~~