#! /usr/bin/perl
Use Expect; #前提是你的服务器上得有Expect包, no installation, no use of interactive
My $PROMPT = ' [\]\$\>\#]\s*$ '; # command Prompt mode for remote system
@a = qw#100.100.100.200 root#; #假设你要登陆的主机ip是100.100.100.200 User is root
$obj = Expect->spawn ("ssh-l $a [1] $a [0]") or die "couldn ' t spawn telnet, $!";
$obj->log_stdout (0); #关闭目标程序的回显
$obj->expect (10,
[Qr/yes\/no:\s*$/i,
sub{my $self = shift; $self->send ("yes\r"); exp_continue;}
],
[Qr/password:\s*$/i,
sub{my $self = shift; $self->send ("123456\r"); exp_continue;}
],
[qr/$PROMPT/,
Sub{my $self =shift; $self->send ("Cd\rtouch 1 2 3\rexit\r"); exp_continue_timeout;}
],
);
# $obj->soft_close (); #关闭目标程序
This article is from the "procedure" blog, make sure to keep this source http://sonwnja.blog.51cto.com/10425150/1662544
Perl Remote Interactive Simple demo version