Solved

SSH access to linux from windows using perl script

Posted on 2011-03-21
17
732 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
  • 8
  • 7
17 Comments
 
LVL 23

Accepted Solution

by:
Kamaraj Subramanian earned 500 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
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35181198
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35181571
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
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 35204733
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

831 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