Hi All:
I am using perl module Net-SSH-Perl but have a little problem: each time I call cmd, a connection/disconnection takes place, even forcing version 2. The problem is that I have to take decisions based on the ouput of each command, so I can not concatenate them with “;”. The ssh server is a tiny Mikrotik router and I don’t want to use much CPU with multiple ssh athentications.
Here is my code (working fine but with multiple connections/disconnections)
#!/usr/bin/perl
use strict;
use IO::Socket;
use IO::Handle;
use Net::SSH::Perl;
my $username = "admin";
my $passwd = "marcos";
my $host = "192.168.1.40";
my %params = (
'privileged'=> 0,
'protocol' => 2,
'port' => 2202,
);
my $ssh = Net::SSH::Perl->new($host, %params);
$ssh->login($username, $passwd);
my $resp = &cambiarplan("1425","997k","1997k","247k","497k");
print "$resp";
sub cambiarplan
{ my $idcliente="$_[0]";
my $drate="$_[1]";
my $dmaxrate="$_[2]";
my $urate="$_[3]";
my $umaxrate="$_[4]";
my ($stdout, $stderr, $exit) = $ssh->cmd(":put [queue tree find packet-mark=cliente$idcliente-bajada]");
if ($exit) {return $stderr};
if ($stdout eq "\r\n") {return "cola de bajada no encontrada\n"};
($stdout, $stderr, $exit) = $ssh->cmd(":put [queue tree find packet-mark=cliente$idcliente-subida]");
if ($exit) {return $stderr};
if ($stdout eq "\r\n") {return "cola de subida no encontrada\n"};
($stdout, $stderr, $exit) = $ssh->cmd("queue tree set [find packet-mark=cliente$idcliente-bajada] limit=$drate max-limit=$dmaxrate");
if ($exit) {return $stderr};
if (not($stdout eq "")) {return $stdout};
($stdout, $stderr, $exit) = $ssh->cmd("queue tree set [find packet-mark=cliente$idcliente-subida] limit=$urate max-limit=$umaxrate");
if ($exit) {return $stderr};
if (not($stdout eq "")) {return $stdout};
return "OK\n";
}
According to module documentation it is possible to run multiple commands con the same connection. Am I doing something wrong?
Thanks in advance,
Julio
|