Perl Remote Interactive Simple demo version

Source: Internet
Author: User

#! /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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.