Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SSH access to linux from windows using perl script

Posted on 2011-03-21
17
Medium Priority
?
938 Views
Last Modified: 2012-05-11
Hi,

I am using active perl, I want perl script to access ssh to linux server from my windows 7

Thanks in advance

0
Comment
Question by:pravink22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
17 Comments
 
LVL 23

Accepted Solution

by:
Kamaraj Subramanian earned 2000 total points
ID: 35181184
http://www.perlhowto.com/execute_commands_on_remote_machines_using_ssh

http://stackoverflow.com/questions/2848725/how-can-i-ssh-inside-a-perl-script
use Net::SSH::Perl;
 
my $host = "perlhowto.com";
my $user = "user";
my $password = "password";
 
#-- set up a new connection
my $ssh = Net::SSH::Perl->new($host);
#-- authenticate
$ssh->login($user, $pass);
#-- execute the command
my($stdout, $stderr, $exit) = $ssh->cmd("ls -l /home/$user");

Open in new window

0
 

Author Comment

by:pravink22
ID: 35181299
Hi,

I am getting this error,

Can't locate Net/SSH/Perl.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/li
b .) at F:\Networking\perl scripting\test\ssh.pl line 1.
BEGIN failed--compilation aborted at F:\Networking\perl scripting\test\ssh.pl li
ne 1.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35181566
type this in command prompt.

And also please refer all the links i posted


ppm install --location=http://www.soulcage.net/ppds Net::SSH::W32Perl

Open in new window

0
 

Author Comment

by:pravink22
ID: 35181672
I am facing trouble with installing Net::SSH::W32Perl

F:\>ppm install --location=http://www.soulcage.net/ppds Net::SSH::W32Perl

Usage:  ppm install [--force] [--nodeps] [--area <area>] <module> | <url> | <file> | <num>
        Run 'ppm help install' to learn more.
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35182072
1) Click Start
2) Click Run
3) Type cmd and press enter
4) Type ppm and press enter
5) Once you get the ppm utility prompt like ppm> type install modulename
eg. install Net::SSH::Perl
The ppm utility will carry the installation of the perl module for you.
0
 

Author Comment

by:pravink22
ID: 35182457
Hi,

Is Net-SSH package is enough ???

I cant find Net::SSH::Perl or Net::SSH::W32Perl
package.jpg
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35182553
if you use Net-SSH, then you have to refer the below link for example code

http://search.cpan.org/~ivan/Net-SSH-0.09/SSH.pm
0
 

Author Comment

by:pravink22
ID: 35195854
This is my perl script, can any one help me??

****************************************************************
#!/usr/bin/perl
use Net::SSH qw(sshopen2);
use strict;

my $user = "yyyyyyyyy";
my $host = "xxx.xxx.xxx.xxx";
my $cmd = "ls";

sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";

while (<READER>) {
  chomp();
  print "$_\n";
}
close(READER);
close(WRITER);
*****************************************************************
output: error
'ssh' is not recognized as an internal or external command,
operable program or batch file.
0
 

Author Comment

by:pravink22
ID: 35204713

can any one help me?? below mentioned scrip is not working
****************************************************************
#!/usr/bin/perl
use Net::SSH qw(sshopen2);
use strict;

my $user = "yyyyyyyyy";
my $host = "xxx.xxx.xxx.xxx";
my $cmd = "ls";

sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";

while (<READER>) {
  chomp();
  print "$_\n";
}
close(READER);
close(WRITER);
*****************************************************************

output: error
'ssh' is not recognized as an internal or external command,
operable program or batch file.
0
 

Author Comment

by:pravink22
ID: 35204749
ya i chked but no use, do u hv any other solution ?
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35204752
what is the exact thing you want to achieve ?

ssh to linux server and do what ?
0
 

Author Comment

by:pravink22
ID: 35204759
ssh to linux server and need to run some commands (like putty)

examples: df -h;date, ls, pwd etc...
0
 
LVL 9

Expert Comment

by:Suhas .
ID: 37319325
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question