nithins has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks
i am using windows locally , i wanted to ssh to linux server & run some command and get the output back.For this i wrote a script but it doesn't seems to be working as i expected.It authenticates that i logged in to server but how to get the output back. i googled a lot but found no success
#!/usr/bin/perl use strict; use warnings; use Net::SSH2; use File::Remote; my $user = ''; my $pass =""; #my $cmd = "ls"; my %host; $host{'portaltest'} = ""; $host{'opatest'} = ""; eval{ foreach my $key (keys(%host)){ my $ssh = Net::SSH2->new(); $ssh->connect($host{$key}); $ssh->auth_password($user, $pass) or die "not able to login\n"; print "password authenticated\n" if ($ssh->auth_ok()); my $chan = $ssh->channel(); $chan->blocking(0); $chan->shell(); $chan->write("ls"); print "ls command executed\n"; select(undef,undef,undef,0.2); my $buf; print $buf while defined (my $len = $chan->read($buf,512)); # print "ls printing\n"; $chan->close(); } }; warn $@ if $@;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Net::SSH2 related query
by salva (Canon) on Nov 19, 2013 at 13:47 UTC | |
Re: Net::SSH2 related query
by lune (Pilgrim) on Nov 19, 2013 at 12:48 UTC | |
Re: Net::SSH2 related query
by keszler (Priest) on Nov 19, 2013 at 14:21 UTC | |
by nithins (Sexton) on Nov 20, 2013 at 06:26 UTC | |
by lune (Pilgrim) on Nov 20, 2013 at 14:40 UTC | |
by keszler (Priest) on Nov 20, 2013 at 14:33 UTC | |
Re: Net::SSH2 related query
by nithins (Sexton) on Nov 19, 2013 at 13:20 UTC | |
by lune (Pilgrim) on Nov 19, 2013 at 14:21 UTC |
Back to
Seekers of Perl Wisdom