Solved

SSH access to linux from windows using perl script

Posted on 2011-03-21
17
711 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Filtering a file to table 9 99
How to send output of ping to syslog (with timestamp and optional comments) 3 186
remove duplicates from the csv file 13 100
syslog unix file 20 68
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

13 Experts available now in Live!

Get 1:1 Help Now