Help - Search - Member List - Calendar
Full Version: ssh to a remote machine
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Vijay Kumar Adhikari
Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.7.10/25 - Release Date: 6/21/2005

MNibble
Vijay Kumar Adhikari wrote:
QUOTE
Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay

Yes there is ..

Net::SSH::Perl

If you ask google "Perl Ssh Perl" you will get the same answer.

Or you can do something like:
my $output = `ssh user@remotehost command_to_get_the_output_from`;

with regard
MNibble

D. J. Birkett
Vijay Kumar Adhikari wrote:
QUOTE
Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay

Did you even bother to search CPAN?
http://search.cpan.org/~ivan/Net-SSH-0.08/SSH.pm

Or atleast google in the very least?
http://www.google.com/search?ie=UTF-8&oe=U...erl+ssh+library

-------------------------
Original Message:
From: Vijay Kumar Adhikari <[Email Removed]>
To: [Email Removed]
Date: Wednesday, June 22 2005 10:33
Subject: ssh to a remote machine
Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.7.10/25 - Release Date: 6/21/2005




--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Zentara
On Wed, 22 Jun 2005 14:18:15 +0545, [Email Removed] (Vijay Kumar
Adhikari) wrote:

QUOTE
Hi,

I need to ssh to a remote machine, run a command and get the output. Is
there some modules that can help.

TIA
Vijay
Here I'll make it easy for you.


##################################################

#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH::Perl;

# If error is:
# Can't locate object method "blocking" via package
#"IO::Handle" at /usr/lib/perl5/site_perl/5.8.6/
# Net/SSH/Perl.pm line 212, <GEN0> line 1.

# then use "protocol => 2";


my %hostdata = (
'localhost' => {
user => "z",
password => "zbaz",
cmdtorun => "ls -la",
misc_data => [],
},


'zentara.zentara.net' => {
user => "z",
password => "foozbarz",
cmdtorun => "/usr/bin/uptime",
misc_data => [],
},


);

foreach my $host (keys %hostdata) {
my $ssh = Net::SSH::Perl->new($host,
port => 22,
debug => 1,
protocol => 2,1

);
$ssh->login($hostdata{$host}{user},$hostdata{$host}{password} );

my ($out) = $ssh->cmd($hostdata{$host}{cmdtorun});
print "$outn";
}

__END__




--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.