Trying to use the same variable name in multiple scripts

Hi guys

I need to run the same script to resolve a number of host names in order for netwatch to work.

Am I correct in saying that I need to use local variables in order for there not to be some sort of clash?

Here’s my script.

{
:local "netwatch-host-name" "nippy"
:local "netwatch-dns-name" "nippy.dyndns.net"
:local "new-dns-ip" [:resolve $"netwatch-dns-name"]
:local "current-dns-ip" [/tool netwatch find comment=$"netwatch-dns-name" host]
:if ($"current-dns-ip" != $"new-dns-ip") do={ /tool netwatch set [find comment=$"netwatch-host-name"] host=$"new-dns-ip"}
}

and then script number two with a new variable name

{
:local "netwatch-host-name" "nippy1"
:local "netwatch-dns-name" "nippy1.dyndns.net"
:local "new-dns-ip" [:resolve $"netwatch-dns-name"]
:local "current-dns-ip" [/tool netwatch find comment=$"netwatch-dns-name" host]
:if ($"current-dns-ip" != $"new-dns-ip") do={ /tool netwatch set [find comment=$"netwatch-host-name"] host=$"new-dns-ip"}
}

I’m worried that the variable

"netwatch-host-name"

is the same for every script.

So essentially I need to resolve the ‘host’ name in netwatch every 30 seconds for a large number of dynamic DNS names.

Should I combine these in one big script or add them together?

Sound like a job for a loop…

Something is certainly in a loop because when I set the scheduler to run those scripts every thirty seconds, the netwatch resets so I get the email notification that my site is up every thirty seconds.

Could this be because I’ve used a local variable and it’s value expires after the script has run? Would using a global variable be better?

Can you see a loop anywhere?

local variables are just that, locally available at the time of script execution. If you want to preserve value you have to go global route and then this variable will be available for the time when router is up and user scripts running. It is similar to scope in c/c++/java

{
:local var
:set var lala
}

var is not accessible any more when script has ended, no matter what

{
:global var
:set var lala
}

var is available. to access it, do the following:
:global var
:put var