CPAN installation Net::ssh: Some problems encountered in the:P Erl _perl

Source: Internet
Author: User
Tags gmp ssh

Use CPAN to install Net::ssh::P erl:
Cpan>install net::ssh::P erl

A number of problems have been encountered during this period for later reading.

Because Cpan's dependence on other software requires that the software version is not too low, upgrade the two modules first:

Copy Code code as follows:

Cpan>upgrade Module::build
Cpan>upgrade Extutils::install

Math::bigint Error:
MATH::BIGINT:COULDN ' t load specified math lib (s), fallback to Math::bigint::calc at/usr/lib/perl5/site_perl/5.8.8/ CRYPT/DH.PM Line 6

Follow the error message and make a change to the sixth line of the dh.pm file:
The original is: Use Math::bigint lib => "Gmp,pari";
MORE: Use Math::bigint try => "Gmp,pari";

During the installation process, when the MATH::GMP module is loaded, the error is stopped. Probably means the lack of gmp.c files, so now the system to install a GMP library files, and a GMP library development package.

Copy Code code as follows:

Aptitude Install Libmath-gmp-perl
Aptitude Search Libgmp3-dev

If the previous installation Math:gmp failed, first the following folder deleted, then install it.
rm-fr/root/.cpan/build/math-gmp-2.06-*

Basic syntax
1. General grammar

Copy Code code as follows:

My $host = "192.168.14.222";
My $user = "root";
My $passwd = "123456";
My%params = (
Protocal => ' 2,1 ',
Debug => ' 1 ',
);
Use net::ssh::P erl;
My $ssh = net::ssh::P erl->new ($host [,%params]);
$ssh->login ($user, $pass);
My ($out, $err, $exit) = $ssh->cmd ($cmd);
print "$out \ n";

2. According to the prompt information, the return character, can realize the interactive operation.

Copy Code code as follows:

$ssh->register_handler ("stdout", sub{
My ($channel, $buffer) = @_;
My $str = $buffer->bytes;
if ($str =~/(. *) \[y\/n\/\?\]/i) {
$channel->send_data ("y\n")
}}
);

3. The Term::readkey module gets an interactive pseudo terminal

Copy Code code as follows:

Use Term::readkey;
ReadMode (' raw ');
$ssh->shell;
ReadMode (' Restore ');


Troubleshoot problems connecting remote hosts slowly

The internet says to install three things:
Yaml
Math::bigint
Math::bigint::gmp

YAML and Math::bigint have been installed before, after loading MATH::BIGINT::GMP test, in the connection with the remote host, the speed significantly increased (connect to the remote host after the operation time unchanged).

Instance

Example 1: Log on to a remote host and complete the simple operation.

Copy Code code as follows:

Use strict;
Use warnings;
Use net::ssh::P erl;
My $host = "192.168.14.222";
My $user = "root";
My $passwd = "123456";
My%params = (
Protocal => ' 2,1 ',
Debug => ' 1 ',
);
My $ssh = net::ssh::P erl->new ($host,%params);
$ssh->login ($user, $passwd);
My ($out, $err, $exit) = $ssh->cmd ("ifconfig");
print "$out \ n";
$ssh->cmd ("Mkdir/home/user;touch/home/user/{1..10}.log");

Example 2: Through a remote host list, login n remote host, complete the interactive operation can be questioned.
Remote host list file Remoto_host_list.txt file:
192.168.14.222 Root 123456
192.168.14.223 Root 123456

Program:

Copy Code code as follows:

Use strict;
Use warnings;
Use net::ssh::P erl;
Open Host_list, "remote_host_list.txt" or Die "can ' t open this file\n";
Sub myssh{
My ($host, $user, $passwd) = split;
My%params = (
Protocal => ' 2,1 ',
# debug => ' 1 ',
);
My $ssh = net::ssh::P erl->new ($host,%params);
$ssh->login ($user, $passwd);
$ssh->register_handler ("stdout", sub{
My ($channel, $buffer) = @_;
My $str = $buffer->bytes;
if ($str =~/(. *) \[y\/n\/\?\]/i) {
$channel->send_data ("y\n")
}}
);
$ssh->cmd ("Aptitude Install PPP");
Print "\n** $host complete...\n\n";
};
while (<HOST_LIST>) {
Myssh
}

Description
According to the given remote host list file, to complete the installation of PPP operation, in the actual installation process, will appear to ask whether to install some dependent packages, such as installation press Y, otherwise press N

The scenario is as follows:
Do your want to continue? [y/n/?]
With "Register_handler", you can implement an interactive automatic installation.

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.