#!/usr/bin/perl -w
use strict;
use warnings;
use Net::SSH2;
#--
my $server='x.x.x.x';
my $user='xxxx';
my $passwd='xxxx';
#--
my $ssh2 = Net::SSH2->new();
print "Connecting to $server...\n";
$ssh2->connect($server) or die 'connect problem';
if( $ssh2->auth_password($user, $passwd)) {
my $chan = $ssh2->channel();
$chan->exec("monitor interface xx.xx");
$chan->exec("q"); ### This is not working
my $buflen = 100000;
my $buf = '0' x $buflen;
$chan->read($buf, $buflen);
print "Starting: $buf ::Ending ";
}
我需要在同一个通道中发送退出命令(exec(" q"))来中断(停止)"监控接口xxxx"命令执行,因为它连续运行。有人请帮帮我。
答案 0 :(得分:0)
您只能在频道上执行一次exec
来电。
我相信您正在尝试向monitor interface xx.xx
编辑的exec
计划提供输入。如果是这样,你应该:
$chan->write("q\n");