I would like to SSH/Telnet into a remote server and grab some info of it. I was trying to get the SSH / Telnet commands to work from the CLI and from within a script.
Has anyone accomplished this? I read quite a couple of posts but couldn’t find my answer, perhaps someone could redirect me.
What I need to accomplish, is to login to an upstream provider’s BGP server. On the server one can find all local (South African) IP Addresses. We would like to use the ISP with the BGP server only for local traffic, and the rest of the traffic should be routed via the other ISP. We used to do this manually, but as the list changes on almost a weekly basis, I would like to automize it.
To see what I mean, Telnet to: route-server.is.co.za and use the command: show ip bgp to show the list over SA IP’s.
The script I need would take all the IP’s, add them to my ROUTE list and specify a variable somewhere set in the script as the gateway.
print “Connecting to $server\n”;
my $session = Net::Telnet->new(Host => $server,Prompt => $prompt,Timeout=>30);
unlink(“t.log”);
$session->dump_log(“t.log”);
$session->waitfor($prompt);
#turn off paging
$session->cmd(“terminal length 0”);
#get list of local routes
print “Retrieving BGP routes\n”;
my @output = $session->cmd(“show ip bgp\n”);
print @output;
print “Route list received\n”;
$session->close;
last
You cannot use telnet/SSH from within RouterOS scripts.
To work around this specific problem, put up a small Linux/BSD/whatever box that retrieves the data for you, mangles the data into whatever you need and then makes it available via HTTP/FTP. You can then use “/tool fetch” within RouterOS scripts to retrieve the result.