What's new

how to read /sbin/ddns_custom_updated

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Pila

Regular Contributor
I need to find out if /sbin/ddns_custom_updated is set to 0 or 1.

How?

I am not asking how to use /sbin/ddns_custom_updated, what is it for or how to set it. Just how to read if it is set to 0 or it is set to 1 in a script.
 
I need to find out if /sbin/ddns_custom_updated is set to 0 or 1.

How?

I am not asking how to use /sbin/ddns_custom_updated, what is it for or how to set it. Just how to read if it is set to 0 or it is set to 1 in a script.

ddns_custom_updated is not a value, it's a program that you run, providing it with either 0 or 1 as argument.
 
ddns_custom_updated is not a value, it's a program that you run, providing it with either 0 or 1 as argument.

That much, unfortunatelly, I understood.

But. I must update it every 30 minutes now. Every day. Double NAT.

My provider rotates my IP address every 30 days.

So, if I could check the state, I could update value once in 30 days (unless I reboot my router or modem) instead od updating it 959 times unnecessary.

I am asking because that check is the only thing standing between my script being as close to perect as possible.

I wanted to fix this detail prior to publishing my script here: custom DDNS script automatically adjusting to single and double NAT, to single or mutiple routers, and configurable for all DDNS services.

Can you include the check in that program? if called without arg, return current value (0 or 1). Please!
 
The value is in nvram.

Code:
nvram get ddns_updated

However, I don't know if that value would revert back to 0 after a WAN IP change. You will have to monitor your IP directly. Have your script store the WAN IP in a file in /tmp/. Through a cron job, re-read the stored IP, and compare it with the current one. If it's different, then it means you have to update your DDNS record, and re-update the stored IP.

Or another method: resolve the DDNS IP with nslookup, then compare it with the current WAN IP. If it's different, refresh your DDNS record.
 
I do not have any other problem All is solved to perfection. As I said, script is quite complex and solves more than anthing I have seen by now. Actually, soves everthing I need (mutliple routers running on single and double NAT situations with backup DDNS, just in case).

I hate to make 959 unnecessary writes of this flag because I can not check it. Also, 959 unnecessary log entires. Actualy, make that 2 * 959 unnecessary log entires (my log and DDNS updated).

I can not remove that ckeck due to double NAT situation. If router restarts, my WAN IP will remain the same, I have it saved in nvram, and by checking, I should need to update router status only the first time. Not other 959 times in 30 days.

OK, is there any way I can preserve a flag or variable in my ddns-script between runs so I can maintan my own state between runs without resroting to writing to nvram? Variable I can keep in RAM and recheck when ddns-script is run the next time? If I have to write to the NVRAM, it is useless, as it does not improve anything.
 
The flag is in nvram. You can read it back in your script:

Code:
FLAG=$(nvram get ddns_updated)

EDIT: corrected name.
 
Last edited:
To be more accurate, ddns_custom_updated does a bit more than just set a single flag. This is the list of what it does:

Code:
  if ((argc == 2 && !strcmp(argv[1], "1")) || (argc == 1)) {
  nvram_set("ddns_status", "1");
  nvram_set("ddns_updated", "1");
  nvram_set("ddns_return_code", "200");
  nvram_set("ddns_return_code_chk", "200");
  nvram_set("ddns_server_x_old", nvram_safe_get("ddns_server_x"));
  nvram_set("ddns_hostname_old", nvram_safe_get("ddns_hostname_x"));
  logmessage("ddns", "Completed custom ddns update");
  } else {
  nvram_set("ddns_return_code", "unknown_error");
  nvram_set("ddns_return_code_chk", "unknown_error");
  logmessage("ddns", "Custom ddns update failed");
  }

  return 0;

In theory, you could even completely replace the ddns_custom_updated call with all these nvram_set() calls (minus the logmessage). If you don't do an "nvram commit" then it won't wear off your nvram, as it will only be written in the RAM copy of nvram.
 
Perfect. Off testing. This seems exactly what I need :)

many thanks for your time and kudos for great work on this fw.
 
Hmm, not returning anything:

Code:
#!/bin/sh
FLAG=$(nvram get dns_updated)
echo "$FLAG"

i wil check your second answer, too
 
Hmm, not returning anything:

Code:
#!/bin/sh
FLAG=$(nvram get dns_updated)
echo "$FLAG"

i wil check your second answer, too

Sorry, missing a "d" here (it's ddns_updated)
 
seems to me I would kill for a source code change in last line:

instead of

return 0;

to be

return (ddns_status);
 
OK, typos :) I was so unpatient :)) I did not check what you wrote, just run it.

It seems it works! Returned 1, now testing, but likely, this is all I needed. many thanks :))
 
hmmm,

#!/bin/sh
/sbin/ddns_custom_updated 0
FLAG=$(nvram get ddns_updated)
echo "$FLAG"

should return 0

and when I change it to 1

#!/bin/sh
/sbin/ddns_custom_updated 1
FLAG=$(nvram get ddns_updated)
echo "$FLAG"

it should return 1.

Not so.
 
From that source code, I can only see what goes on with 1. I see nothing saving 0.

There must be more. Because, when I start with state of 1, I can repeat the code as many times as I want, and I will never get 0 as response.

Code:
#!/bin/sh
/sbin/ddns_custom_updated 0
FLAG=$(nvram get ddns_status)
echo "$FLAG"
 
My GUI shows correctly, on the first page, DDNS status. It is correctly updated after I run above script changing from 0 to 1 and back. But, I never get correct answer from FLAG=$(nvram get ddns_status)

OK, which line runs this check for first page of GUI? It reads it correctly. I can not.
 
source code says

FLAG=$(nvram get ddns_status)

will never ever change from 1. It may be 0 after a reboot, but this can also be a garbage after a reboot as I do not know who and where and if initialises variables.

FLAG2=$(nvram get ddns_return_code)

this changes from "unknown_error" to "200"

But, this does not seem like something I can rely on since I do not have a clue who else can change this value and in which state will it be after a boot. I will try with this second example, but this seems not OK but guerilla to me. Afraid to rely on this.

If this is ALL the code writing to the ddns_return_code, I am OK, but I can never be sure it will not go boooom. Without reading all of the source code.

Obeying existing programming style (I do not like it),

after } else {, the first line should be:
nvram_set("ddns_status", "0");
 
OK, I can use

FLAG=$(nvram get ddns_return_code)

which changes from "unknown_error" to "200" for 0 and 1.

But, this seems faaaaar from legit. Will need to do testing and will never be able to be sure it will not break my code. Without reading entire source code, that is.
 
Just to make sure everyone is on the same page......ddns_custom_updated does nothing to reflect the current status of the ddns. It just signals, and sets some vars (primarily for the use of ezipupdate) on the success or fail status of the LAST attempted update. If the address should change (even 1 second after you run ddns_custom_updated), nothing will happen with any of the ddns vars.

From what I read you want to accomplish, you need to set up a poll to check the last ddns address that was set vs the current ip address as Merlin suggested (this is how the built in watchdog for some of the ddns providers works).
 
[QUOTE="john9527, ddns_custom_updated does nothing to reflect the current status of the ddns. It just signals, and sets some vars (primarily for the use of ezipupdate) on the success or fail status of the LAST attempted update. .[/QUOTE]

Seemingly, it sits on 1 entire life. Maybe after a reboot is not 1.

OK, back to my complex DDNS script: While double NAT, I check external IP on my own. If external IP is the same as 30 minutes before, I know that since I saved previous value.

Now, nothing changed, I need not issue:

/sbin/ddns_custom_updated 1

as nothing changed. So, no point to update anything and write to NVRAM. Correct?

But. When my router (Double NAT) reboots (modem remains ON), and the very first check I perform will need to set

/sbin/ddns_custom_updated 1

and then, I do not need to set it again until my IP changes (30 days later), my modem reboots or my router reboots.
 
Judging from the source doe Merlin was kind to offer, ths works as I need:

FLAG=$(nvram get ddns_return_code)

which changes from "unknown_error" to "200" for 0 and 1.

But, this does not seem to me like legit as I do not know who can and when change these values. I will use it, but it may break at any time if anything else (outside source doe shown above) can change these values.

nvram_set("ddns_status", "1");

should change according to input 0 or 1 and not be hardcoded, at least.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top