I am currently experimenting with Netwatch and ran into a limitation. It seems that global variables are discarded between runs.
Test setup:
/system/script add dont-require-permissions=no name=nw-globals owner=me policy=read,write,test source=\
":global foo;\
\n:set foo (\$foo+1);\
\n:log info (\$foo);"
/tool/netwatch/add host=1.1.1.1 test-script=nw-globals type=icmp
This produces the following log:
2026-05-08 11:47:02 script,info 1
2026-05-08 11:47:12 script,info 1
2026-05-08 11:47:23 script,info 1
2026-05-08 11:47:32 script,info 1
However, when I run the script manually multiple times using /system/script/run nw-globals, the variable persists as expected:
2026-05-08 11:39:17 script,info 1
2026-05-08 11:39:19 script,info 2
2026-05-08 11:39:20 script,info 3
The documentation states that Netwatch executes scripts as the *sys user:
Netwatch executes scripts as *sys user, so any defined global variable in the Netwatch script will not be readable by for an example a scheduler or other users
My understanding was that as long as *sys is executing the script, the global variables should persist between runs.
As a workaround, I currently :serialize variables to JSON file and restore them using :deserialize at script startup. This works, but I would prefer a simpler approach.
Could this be a bug or an intentional limitation? I found several older discussions about issues with global variables, but I could not find a definitive answer or workaround.