using Net::SSH2 shell 的二个方法

时间:2022-09-26 08:13:15

方法一:

复制代码 代码如下:

$chan2 = $ssh2->channel();
$chan2->blocking(0);
print $chan2 "tail -5 /var/log/authlog\n";
print "**$_" while <$chan2>;

 

方法二:

复制代码 代码如下:

#shell use
my $chan2 = $ssh2->channel();
$chan2->shell();
print $chan2 "uname -a\n";
print "LINE : $_" while <$chan2>;
print $chan2 "who\n";
print "LINE : $_" while <$chan2>;
$chan2->close;