Re: [Ssh-sftp-perl-users] Net::SSH2::Channel read and write methods
Brought to you by:
dbrobins
From: Enrique de A. S. <enr...@pc...> - 2006-03-16 16:09:36
|
Hi, But with this example it's only possible to get the standard output of the executed commands. Do you know how to get the standard error (separated from the stdout)? Thanks, Enrique. Rob Verduijn wrote: > Hi there, > > I asked the same kinda question and did get an answer from Bryan Bueter. > With his help I managed to come up with the following example: > > > ###########begin > #!/usr/bin/perl > > # use warnings and strict to force neat coding, > # and prevent bugs in the future > use warnings; > use strict; > > use Net::SSH2; > > # some variables > my $remotehost="10.9.8.7"; > my $remotefile="/etc/passwd"; > my $localfile="copyoffpasswd"; > # this is not smart , make sure your scripts can run as non-root > my $login="root"; > # this is not smart , plain text password, use a keypair > my $password="verysecretpasswordinplaintext"; > 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)); > > # using exec to execute a command > $chan=$ssh2->channel(); > $chan->exec('uname -a'); > print "EXEC : $_" while <$chan>; > > # don't forget to close since you can do only 1 exec > $chan->close; > > # this is a get example, I think you can figure out the put version > $ssh2->scp_get($remotefile,$localfile); > > # writing to a channel > # a new channel, remember the last one is closed > $chan=$ssh2->channel(); > $chan->shell(); > print $chan "uptime\n"; > print $chan "who\n"; > # reading from a channel > print "SHELL: $_" while <$chan>; # lets see what the output is > > # clean up afterwards > $chan->close; > ########end > > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > > > |