#!/usr/bin/perl

## Create a text file with each of your routers' IPs, login name, and password.
## Run this program, give it that text file as the only argument.

use Net::SSH::Perl;
## You really also want Math::BigInt::GMP too. Trust me.

sub do_one_host {
  ($host, $user, $pass) = @_ ;
  my $dest = 'mikrotikbackups@example.com';
  my $ssh = Net::SSH::Perl->new($host);
  $ssh->login ($user, $pass);

  my $exportcmd = "/export file=$host";
  my($stdout,$stderr,$exit) = $ssh->cmd($exportcmd);
  my $sendcmd = "/tool e-mail send subject=\"Backup of $host\" file=$host.rsc to=\"$dest\" from=\"router\@example.com\" server=my.mail.server" ;
  my($stdout,$stderr,$exit) = $ssh->cmd($sendcmd);

  return $true;
}

open FILE, $ARGV[0] or die $!;
while (<FILE>) {
  ($host, $user, $pass) = split(' ', $_);
  print "Visiting $host.\n" ;
  ## do_one_host($host, 'admin' , 'SecretPass' );
  do_one_host($host, $user, $pass);
}