I am trying to test this script to see where it is going wrong, but how do I do it?? I have copied and pasted it into terminal, but it doesn’t seem to hold the local variables… Any ideas, sorry I am new to this;
define variables
:local list
:local comment
:local newip
Loop through each entry in the address list.
:foreach i in=[/ip firewall address-list find] do={
Get the first five characters of the list name
:set list [:pick [/ip firewall address-list get $i list] 0 5]
If they’re ‘host_’, then we’ve got a match - process it
:if ($list = "host_") do={
Get the comment for this address list item (this is the host name to use)
:set comment [/ip firewall address-list get $i comment]
Resolve it and set the address list entry accordingly.
:set newip [:resolve $comment]
/ip firewall address-list set $i address=$newip}}
The router doesn’t ‘hold’ local variables. The values are cleared when the script terminates. If you want them to retain the values, use global instead.
So the best way to test it is to use global vars and run it though terminal to see the output? I have tried running the script from command line and all I get is failure at the moment! I guess essentially I want a way to debug it..
Are you escaping the dollar sign ($) and quotes (") in the script? Looks like it in the code. There should be no leading backslash. Like this:
:set list [:pick [/ip firewall address-list get $i list] 0 5]
ADD: I use the log to troubleshoot my code. After every section of code, I use this:
:log info "made it here #1"
Then run the script and see where the log entries stop.
And for format errors, there is nothing like the CLI script editor. The code that contain no errors will be in color. Where there is an error, the text changes to white. Like Dorothy gets to Oz! Follow the yellow brick road!