Code: Select all
# Set needed variables
:local username “<username>"
:local password “<password>"
:local hostname “<hostname>"
:global dyndnsForce
:global previousIP
# print some debug info
#:log info ("UpdateDynDNS: username = $username")
#:log info ("UpdateDynDNS: hostname = $hostname")
#:log info ("UpdateDynDNS: previousIP = $previousIP")
# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/usb1/dyndns/dyndns.checkip.html"
:local result [/file get usb1/dyndns/dyndns.checkip.html contents]
# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
#:log info "UpdateDynDNS: currentIP = $currentIP"
# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true
# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/usb1/dyndns/dyndns.txt"
:local result [/file get usb1/dyndns/dyndns.txt contents]
# :log info ("UpdateDynDNS: Dyndns update needed")
# :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:log info ("UpdateDynDNS: Update needed - previousIP = $previousIP / currentIP = $currentIP [Result: $result]")
:set previousIP $currentIP
# :put ("Dyndns Update Result: ".$result)
} else={
# :log info ("UpdateDynDNS: currentIP = $currentIP - No dyndns update needed")
}
This script has the option to force an update by setting the ":set dyndnsForce true" command. Rather than do this in this script (which would force an update every time) I want to have another script, which only runs once a day which changes this global variable to true. Then this main script will do a forced update once a day.
The problem is I can't get this to work, so my understanding of global variables is flawed I guess?
When using global variables across 2 scripts I assume I need to declare them in both scripts with ":global dyndnsForce"
This is what I have in my 2nd script:
Code: Select all
:global dyndnsForce
:set dyndnsForce true
FYI I'm running 6.21.1