[Ssh-sftp-perl-users] register_handler and Net::SSH::Perl question
Brought to you by:
dbrobins
|
From: Shapiro, D. <dav...@it...> - 2004-06-03 13:17:29
|
This is probably a simple one for those who know this stuff. I am trying to
do something real simple as a test. Basically, I want to run
/usr/local/bin/sudo /usr/sbin/format c1t0d0 and when it sees the format>
prompt I want it to exit. I tried to use the register_handler, but it
pauses. I end up typing "quit" myself to get it to exit. It displays the
$str content, but $out does not show anything. I was expecting the handler
to see format> and type quit for me, but it does not do it. I tried
interactive => 0 in new, but that did not work. I tried setting handler to
look at stderr just in case format stuff went to that handle instead of
stdout like the passwd example, but that did did not work either.
#!/usr/local/bin/perl
use Net::SSH::Perl;
use Net::SSH::Perl::Constants qw( :msg2 );
my $ssh = Net::SSH::Perl->new(
"falcon",
debug => 1,
protocol => 2,
options => [
"RhostsRSAAuthentication yes",
"HostbasedAuthentication yes",
#"UsePrivilegedPort yes",
"PreferredAuthentications
publickey,hostbased,password,keyboard-interactive",
"EnableSSHKeysign yes"
]
);
$ssh->login("nagios");
$ssh->register_handler("stdout", sub {
my($channel, $buffer) = @_;
my $str = $buffer->bytes;
print "string: $str\n";
if ($str =~ /format>/) {
$channel->send_data("quit\r");
}
});
my ($out,$err,$rc) = $ssh->cmd("/usr/local/bin/sudo /usr/sbin/format
c1t0d0");
print "out: $out\n";
print "err: $err\n";
|