I have written a script to add host routes to the IPv4 routing table, please see the complete script below. The problem however is that on each invocation, the script creates duplicate entries in the routing table, and of course it does not delete old entries (which it created when the IP addresses were different). Can you please advise me some way to detect obsolete entries? It would be nice to use some timestamps on configuration entries, but I don't know of such a feature existing in RouterOS.
The script itself:
Code: Select all
# extract addresses in the list
:local AddressList [/ip firewall address-list find comment~"api\\."];
:local ipAddress;
:foreach entry in=$AddressList do={
:set ipAddress ([/ip firewall address-list get $entry]->"address");
:put ($ipAddress."/32");
/ip/route/add comment=([/ip firewall address-list get $entry]->"comment") disabled=no distance=1 dst-address=($ipAddress."/32") gateway=10.x.x.x routing-table=main;
};
Code: Select all
# delete all API routes
/ip/route/remove [find comment~"api\\."];