Solved

SSH access to linux from windows using perl script

Posted on 2011-03-21
17
698 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:pravink22
Comment Utility
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
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
Comment Utility
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
Comment Utility
0
 

Author Comment

by:pravink22
Comment Utility
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
Comment Utility
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
Comment Utility
Hi,

Is Net-SSH package is enough ???

I cant find Net::SSH::Perl or Net::SSH::W32Perl
package.jpg
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 23

Expert Comment

by:Kamaraj Subramanian
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
0
 

Author Comment

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

Expert Comment

by:Kamaraj Subramanian
Comment Utility
what is the exact thing you want to achieve ?

ssh to linux server and do what ?
0
 

Author Comment

by:pravink22
Comment Utility
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 .
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
This video discusses moving either the default database or any database to a new volume.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now