Re: [Ssh-sftp-perl-users] net::ssh2 perl small program wanted!!!!
Brought to you by:
dbrobins
From: Brian H. <bh...@ne...> - 2008-05-07 20:51:57
|
Ibrahim, You might want to try opening up a shell on the channel. See the following code excerpt: my $chan = $ssh->channel(); $chan->blocking(0); $chan->shell(); #send the command to the server through the data channel print $chan "whereis rkhunter\n"; #get the output from the command and push it onto the array while(<$chan>) { push(@output, $_); } Ibrahim Salloum wrote: > Hello everybody, > > i need urgently an net::ssh2 perl small program that connects to a > router and execute one command and display its output in the sceen. i > wrote one but it didn t give me the result i need: > > #!/usr/bin/perl -w > # use warnings and strict to force neat coding, > # and prevent bugs in the future > use strict; > use Net::SSH2; > > my $remotehost="kdca-guard-agm1"; > my $login="reports"; > my $password="wvyonfr5"; > my $chan; > # creating the ssh2 object > my $ssh2 = Net::SSH2->new(); > # connecting and logging in to the machine > die "connect fail" unless ($ssh2->connect($remotehost)); > die "password fail" unless ($ssh2->auth_password($login,$password)); > > $chan=$ssh2->channel(); > $chan->exec("sh ver\n"); > print "EXEC : $_" while <$chan>; > $chan->close; > print "connected\n"; > the favor ll be returned > best regards, > > thank you > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > ------------------------------------------------------------------------ > > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > -- Brian Hill NEXCESS.NET Internet Solutions http://nexcess.net 304 1/2 S. State St. Ann Arbor, MI 48104 1.866.NEXCESS |