EDIT:http://www.dysan.net/Perl/lg.php-- Original script.
You put a file named monitor.passwd in your etc directory....
/etc/monitor.passwd: admin||blah01
/somewhere/txtfile.txt: /ip dhcp-server lease print
ssh-cmd 127.0.0.1 txtfile.txt
and it should send all the commands in txtfile.txt to the router! I am successfully using this script to take all the static ip address entries in my mysql db (30-40 er so) and pull them into the mikrotik's dhcp server. It works great!
#!/usr/bin/perl # by Ian Redden (c) 2005 # Purpose: to get info off of a router for looking glass. # #-varibles use Expect; $ssh = "/usr/bin/ssh"; $router = "$ARGV[0]"; $txtfile = "$ARGV[1]"; #-get username/password open(PS,"/usr/local/mikrotik/monitor.passwd"); while () { chomp; ($usernm,$pass) = split(/\|\|/, $_); } close(PS); $command = "$ssh -l $usernm $router"; #-connect to router. $ssh = Expect->spawn("$command"); $ssh->log_stdout(1); #-check to see if dsa authenticity question appears if ($ssh->expect(2, "yes/no")) { print $ssh "yes\r"; } #-send password. if ($ssh->expect(undef, "password:")) { print $ssh "$pass\r"; } #-send command. open( FILE, "< $txtfile" ) or die; if ($ssh->expect(undef, ">")) { while ($cmd = ) { print $ssh "$cmd\r"; $ssh->expect(undef, ">"); } } close FILE; print $ssh "/quit\r";