Chinaunix首页 | 论坛 | 博客
  • 博客访问: 821881
  • 博文数量: 188
  • 博客积分: 4433
  • 博客等级: 上校
  • 技术积分: 1905
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-14 07:14
个人简介

linux

文章分类

全部博文(188)

文章存档

2016年(6)

2015年(22)

2014年(18)

2013年(5)

2012年(125)

2011年(10)

2010年(2)

分类: Python/Ruby

2012-05-17 16:26:45

参看这篇

#!/usr/bin/perl
use Expect;
$Expect::Log_Stdout = 1;
 
$ENV{TERM} = "vt100";
 
my ($host,$pass) = ("host","passwd");
my $exp = Expect->new;
$exp = Expect->spawn("ssh -l root $host");
$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);
阅读(924) | 评论(0) | 转发(0) |
0

上一篇:shell expect

下一篇:常见的nginx的配置选项

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