Re: [Ssh-sftp-perl-users] Net::SSH2 example
Brought to you by:
dbrobins
From: Rob V. <rob...@br...> - 2006-02-14 13:45:55
|
Hi there, Many thanx for the example, I got it to work. This is the code I used: --Start--> #!/usr/bin/perl use warnings; use strict; use Net::SSH2; my $ssh2 = Net::SSH2->new(); print "connect fail\n" unless ($ssh2->connect('testbox')); print "password fail\n" unless ($ssh2->auth_keyboard('root','*******')); my $chan=$ssh2->channel(); $chan->shell(); print $chan "uname -a\n"; print "LINE : $_" while <$chan>; print $chan "who\n"; print "LINE : $_" while <$chan>; $chan->close; <--end-- and the output: --start--> LINE : Linux testbox 2.6.5-7.111.19-smp #1 SMP Fri Dec 10 15:10:58 UTC 2004 i686 i686 i386 GNU/Linux LINE : root pts/0 Feb 14 14:33 (robspc) <--end-- As you can see I can push more than one command to a channel after I read from the channel. Don't know why this isn't working for you, if you want to know what version libs I use let me know which ones you want hear about. Thanx Rob Op ma, 13-02-2006 te 09:39 -0500, schreef Bryan Bueter: > The best I could come up with is this: > > --- snip ---> > use Net::SSH2; > > my $ssh2 = Net::SSH2->new(); > $ssh2->connect("127.0.0.1"); > $ssh2->auth(username => scalar getpwuid($<), interact => 1) or die; > print "\n"; > > my $chan = $ssh2->channel(); > $chan->shell(); > > print $chan "uptime\n"; > print $chan "who\n"; > print "LINE: $_" while <$chan>; > <--- end --- > > The problem is that once you read from the channel, you no longer seem to > be able to interact with it. So in the above code, you will see your > uptime and who output, but in the following, all you see is your uptime > output: > > --- snip ---> > print $chan "uptime\n"; > print "LINE: $_" while <$chan>; > > print "LINE: $_" while <$chan>; > print $chan "who\n"; > <--- end --- > > I suppose this is a bug, but its been difficult to get anything more > meaningfull then "read operations seem funny". And I just havnt had time > to play with it more. > > I hope this gets you further then you were before. > > > Bryan > http://www.sourceforge.net/projects/rover > > > Hi everyone, > > > > I'm trying to get Net::SSH2 to work but I'm kinda stuk after the > > connection is made. > > > > Could anyone provide an example on how to set up a connection, give a > > remote command, and then read the output of that command(either stdout > > or stderr) > > > > I would also apreciate an example of the use of chan->shell(); on how to > > put several commands into that one and how to read the output of those > > commands (stderr and stdout again) > > > > Thanx > > Rob > > > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > > files > > for problems? Stop! Download the new AJAX search engine that makes > > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 > > _______________________________________________ > > Ssh-sftp-perl-users mailing list > > Ssh...@li... > > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users |