Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl Monk, Perl Meditation
 
PerlMonks  

Communication between Windows and Linux via Perl

by zhonghua (Novice)
on Apr 10, 2013 at 15:05 UTC ( #1027993=perlquestion: print w/ replies, xml ) Need Help??
zhonghua has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I want to use a script on Windows to execute some commands on Linux, then return the command results.

I put the Linux RSA identity file "id_rsa" under C: direcoty. And the following is my code:

---------------------clip-------------------------
#!/usr/bin/perl -w use strict; use Net::SSH::Perl; $ENV{HOME} = "C:"; my $host = "192.168.32.138"; my $user = "root"; my $passwd = "101010"; my %params = ( protocal => '2,1', # debug => '1' ); my $ssh = Net::SSH::Perl->new($host,%params); $ssh->login($user,$passwd); my ($stdout, $stderr, $exit) = $ssh->cmd("ls /home"); print "$stdout";
---------------------clip-------------------------

When I run this script, there are so many problems showed as following.

Can't locate Math/Pari.pm in @INC (@INC contains: c:/Perl64/site/lib c:/Perl64/lib .) at C:/Perl64/site/lib/Net/SSH/Perl/Util/SSH2MP.pm line 6, <GEN1> line 1.

BEGIN failed--compilation aborted at c:/Perl64/site/lib/Net/SSH/Perl/Util/SSH2MP.pm line 6, <GEN1> line 1.

Compilation failed in require at c:/Perl64/site/lib/Net/SSH/Perl/Util.pm line 56, <GEN1> line 1.

BEGIN failed--compilation aborted at c:/Perl64/site/lib/Net/SSH/Perl/Kex/DH1.pm line 10, <GEN1> line 1.

Compilation failed in require at c:/Perl64/site/lib/Net/SSH/Perl/Kex.pm line 6, <GEN1> line 1.

BEGIN failed--compilation aborted at c:/Perl64/site/lib/Net/SSH/Perl/Kex.pm line 6, <GEN1> line 1.

Compilation failed in require at c:/Perl64/site/lib/Net/SSH/Perl/SSH2.pm line 6, <GEN1> line 1.

BEGIN failed--compilation aborted at c:/Perl64/site/lib/Net/SSH/Perl/SSH2.pm line 6, <GEN1> line 1.

Compilation failed in require at c:/Perl64/site/lib/Net/SSH/Perl.pm line 52, <GEN1> line 1.

---------------------clip-------------------------

I try to use module Net::SSH to execute this idea, but I don't know how to handle the trust relationship between Windows and Linux.

coud you help me to check and resolve this problem? Or give me another idea for the communication between windows and Linux?

Thank you.

Best Regards,

Wei

Comment on Communication between Windows and Linux via Perl
Download Code
Re: Communication between Windows and Linux via Perl
by tobyink (Abbot) on Apr 10, 2013 at 15:31 UTC

    "Can't locate Math/Pari.pm in @INC"

    Start by installing Math::Pari.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

        I recently implemented something like this with Net::SSH::Any... Here's a code snippet...

        my $ssh = Net::SSH::Any->new($ipAddr, user => $user, password => $password, backends => [qw/Net::SSH2/], timeout=>1, kill_ssh_on_timeout=>1); $ssh->error and die "Unable to Connect via SSH to $mac, " . $ssh->error); my ($output, $errput) = $ssh->capture2($cmd);

        Hi,

        Thank you, I'll try to use Net::SSH::Any.

        Br, Wei
Re: Communication between Windows and Linux via Perl
by hbm (Hermit) on Apr 10, 2013 at 15:41 UTC

    Evidently Math::Pari failed to install. I ran into this recently, and:

    1. Copied .cpan/sources/authors/id/I/IL/ILYAZ/modules/Math-Pari-2.01080605.tar.gz into a working directory.
    2. Untar'd it, and changed into the uncompressed Math-Pari directory.
    3. Fetched and untar'd http://megrez.math.u-bordeaux.fr/pub/pari/unix/OLD/pari-2.1.7.tgz.
    4. perl Makefile.PL; make; make install

    For #4, on Windows, you'll probably use some other 'make'. See what 'perl -V:make' says.

        "You don't have a Perl Package Manager you can use to install Math::Pari? That's how I get my packages. It even notes any dependencies you need for packages you want to install and automatically installs those as well, preventing problems like this."

        Both ActiveState and Strawberry Perl have shipped with PPM and cpan for several years now. ActiveState doesn't ship with a C compiler or build tools, though they can be installed via ppm MinGW though currently only for the 32bit platform (note OP is using a 64bit perl), if you want to work with ActiveState 64bit you have to install this yourself.

        With a little effort installing modules and their dependencies via cpan is reasonably straightforward. IMHO any automated system for module installation is going to have it's short comings, and for cpan that (again, IMHO) is the level of verbose output you get on failure. It seems simply to confuse those who aren't used to software compilation. In other words those who are new, and this can be very discouraging. Perhaps we can work on that.

        Some of the popular PPM repos have been reported to me as 'out of date' or 'behind the times' recently. Part of that is perhaps due to them being run by individuals. I'm currently drafting a module installation tutorial covering modern module installation methods, and a FAQ on the subject. This will be posted for critique in the usual place before it makes it to tutorials.

        Hi,

        thank you :). I try to download a nmake application, but to my surprise, I didn't find it from Micorsoft Website, while I didn't use Visual Studio. Fortunately, I found the dmake application and it can be used to install the perl module.

        according to so many warm-hearted friends' advise, I found I didn't install the Net::SSH::Perl module correctly. I'm planning to re-install this module.

        Thank you so much

        Br, Wei

      Thank you, I have installed dmake to compile and isntall the Net::SSH::Perl module.

      Maybe I need to re-install it. Thank you.

      Br, Wei
Re: Communication between Windows and Linux via Perl
by Anonymous Monk on Apr 11, 2013 at 04:56 UTC
    If you're going to recent version of your Distro's with Openssh 4+, try using Net::OpenSSH it works.

      Hi,

      I have tried to install this Net::OpenSSH, but this module can't installed on Windows platform. So I choose the Net::SSH::perl.

      Anyway, thank you

      Br, Wei
Re: Communication between Windows and Linux via Perl
by perl514 (Pilgrim) on Apr 11, 2013 at 06:10 UTC

    Hi,

     

    You can try DWIM Perl. It comes with the Net::SSH2 Module pre installed. I have used it to login to a lot of Linux Boxes and Linux Based Storage Arrays and it works like a charm. Do a google search for DWIM Perl.

    For Net::SSH2, please read A little demo for Net::SSH2. Its really good. One thing that will help you is, insert a sleep interval -  sleep 10 in your script right after you do a chan2->exec('somecommand');.

    Perlpetually Indebted To PerlMonks

    use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";
    http://dwimperl.com/windows.html is a boon for Windows.

      One thing that will help you is, insert a sleep interval - sleep 10 in your script right after you do a chan2->exec('somecommand');

      That is not required when the module is used correctly.

        Hi Salva,

         

        Thank you for pointing that out. I have been using the module as shown in a tutorial posted here, but not sure where I am going wrong. I will be thankful if you could provide any pointers on how to use it correctly.

        Perlpetually Indebted To PerlMonks

        use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";
        http://dwimperl.com/windows.html is a boon for Windows.

      hi,

      Thank you for you good advice. :) Now I'm using Active Perl and Active Python, I'm used to Active product. I'll try it.

      Thank you.

      Br, Wei
Re: Communication between Windows and Linux via Perl
by pvaldes (Hermit) on Apr 11, 2013 at 09:44 UTC
    Or give me another idea

    Ext2Read?

Re: Communication between Windows and Linux via Perl
by ambrus (Abbot) on Apr 11, 2013 at 21:13 UTC

    Install putty to your machine. This comes with plink, a command-line ssh client that doesn't use a terminal emulator window on the client side. Import your keyfile to the PuttyGen program and save it in putty's private key file format. Spawn plink from your perl script with something like

    $error = system q(plink -i yourkeyfile.ppk root@192.168.32.138 "ls /ho +me" > outputfile.txt);

    Then, if $error is false, read the output file.

      Hi

      Good idea. Very thanks. I'll try it.

      Up to now, the problem is still existing, but I'm too busy to finish this script. Some days later, I'll change a new environment and try again. Then I'll post the new progress.

      Thanks and Best Regards, Wei

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027993]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-04-21 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (494 votes), past polls