[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 983
  • Last Modified:

SSH access to linux from windows using perl script

Hi,

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

Thanks in advance

0
pravink22
Asked:
pravink22
  • 8
  • 7
1 Solution
 
Kamaraj SubramanianApplication Support AnalystCommented:
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
 
pravink22Author Commented:
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.

 
Kamaraj SubramanianApplication Support AnalystCommented:
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
 
pravink22Author Commented:
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
 
Kamaraj SubramanianApplication Support AnalystCommented:
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
 
pravink22Author Commented:
Hi,

Is Net-SSH package is enough ???

I cant find Net::SSH::Perl or Net::SSH::W32Perl
package.jpg
0
 
Kamaraj SubramanianApplication Support AnalystCommented:
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
 
pravink22Author Commented:
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
 
pravink22Author Commented:

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
 
pravink22Author Commented:
ya i chked but no use, do u hv any other solution ?
0
 
Kamaraj SubramanianApplication Support AnalystCommented:
what is the exact thing you want to achieve ?

ssh to linux server and do what ?
0
 
pravink22Author Commented:
ssh to linux server and need to run some commands (like putty)

examples: df -h;date, ls, pwd etc...
0
 
Suhas .QA ManagerCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now