What's new

DNS-O-Matic updater script

  • 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!

maghuro

Very Senior Member
What it does is that it updates your DNS-O-Matic hostname.
It's pretty simple, and very badly coded, but hey.. it works!
Suggestions are appreciatted here, or via pull request on github:
https://github.com/maghuro/stuff/blob/master/dnsomatic

Install with:
Code:
/usr/sbin/curl -s --retry 3 https://raw.githubusercontent.com/maghuro/stuff/master/dnsomatic -o /jffs/scripts/dnsomatic && chmod 755 /jffs/scripts/dnsomatic && ln -s /jffs/scripts/dnsomatic /opt/bin/dnsomatic

For the first run:
Code:
dnsomatic set USERNAME YourUsername
dnsomatic set PASSWORD YourPassword
dnsomatic set HOSTNAME YourHostname (usualy all.dnsomatic.com)

Then, list of available commands:
Code:
dnsomatic config # list of contents of config file
dnsomatic cron X # creates the cronjob, where X is the number of minutes for each IP check
dnsomatic init # you can use it on wan-event connected, for example. The only thing it does is to give a 30s sleep before first update
dnsomatic force # forces an update even if the current IP is the same
dnsomatic force 11.11.11.11 country # forces an update to the given IP. Country is optional
Thanks @Jack Yaz for the Print_Output code.

I recommend to add the following line on services-start:
Code:
/jffs/scripts/dnsomatic cron 5 #dnsomatic cronjob
 
This is what i do.
Code:
cat > /jffs/scripts/dnsomatic.sh <<'EOF'
#!/bin/sh
# Update the following variables:
USERNAME=Username
PASSWORD=Password
HOSTNAME=all.dnsomatic.com


/usr/sbin/curl -k --silent -u "$USERNAME:$PASSWORD" "https://updates.dnsomatic.com/nic/update?hostname=$HOSTNAME&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG&myip=" &>/dev/null

EOF
chmod 755 /jffs/scripts/dnsomatic.sh
}

for the cronjob, place in services start.

Code:
cru a DNS-O-Matic "*/30 * * * * sh /jffs/scripts/dnsomatic.sh"
 
What it does is that it updates your DNS-O-Matic hostname.
It's pretty simple, and very badly coded, but hey.. it works!
Suggestions are appreciatted here, or via pull request on github:
https://github.com/maghuro/stuff/blob/master/dnsomatic

Install with:
Code:
/usr/sbin/curl -s --retry 3 https://raw.githubusercontent.com/maghuro/stuff/master/dnsomatic -o /jffs/scripts/dnsomatic && chmod 755 /jffs/scripts/dnsomatic && ln -s /jffs/scripts/dnsomatic /opt/bin/dnsomatic

For the first run:
Code:
dnsomatic set USERNAME YourUsername
dnsomatic set PASSWORD YourPassword
dnsomatic set HOSTNAME YourHostname (usualy all.dnsomatic.com)

Then, list of available commands:
Code:
dnsomatic config # list of contents of config file
dnsomatic cron X # creates the cronjob, where X is the number of minutes for each IP check
dnsomatic init # you can use it on wan-event connected, for example. The only thing it does is to give a 30s sleep before first update
dnsomatic force # forces an update even if the current IP is the same
dnsomatic force 11.11.11.11 country # forces an update to the given IP. Country is optional
Thanks @Jack Yaz for the Print_Output code.

I recommend to add the following line on services-start:
Code:
/jffs/scripts/dnsomatic cron 5 #dnsomatic cronjob
Your script looks pretty nice. good job.
 
It does look like a nice script, you've obviously put a bit of time into it, and a great starting point for others who are looking at writing script for things. Don't take this the wrong way, but if a user can figure out how to download, edit and run this script, I would hope they could write the one liner that needs to get added to a Cron task to update the DDNS entry :)
(My DDNS provider provides me with cut and paste options for Cron, shell scripts, etc with the appropriate (encrypted) values. Personally I don't like sending usernames and passwords as part of a url)
 
Dns o matic is a selectable option in the fw, I'm not sure why a script is needed for this? It looks good, but I don't see why it is needed over the existing option
 
@maghuro you clutter up the /jffs/configs folder with an file that does not belong there.
Move settings for /jffs/scripts/ scripts to the /jffs/addons/<your addon name> folder.
 
Dns o matic is a selectable option in the fw, I'm not sure why a script is needed for this? It looks good, but I don't see why it is needed over the existing option
For those like me who are behind a double NAT situation, where a wan IP change isn't detected by the native updater...


That was the problem I had and that's why I've written this
 
Last edited:
It does look like a nice script, you've obviously put a bit of time into it, and a great starting point for others who are looking at writing script for things. Don't take this the wrong way, but if a user can figure out how to download, edit and run this script, I would hope they could write the one liner that needs to get added to a Cron task to update the DDNS entry :)
(My DDNS provider provides me with cut and paste options for Cron, shell scripts, etc with the appropriate (encrypted) values. Personally I don't like sending usernames and passwords as part of a url)
This script was my entry point for Bourne shell programing. It was a necessity and I started to test this and that!
The main objective was to deal with the frequent ip changes of my provider and to not abuse the dnsomatic API (that's why it writes the current IP to do a local comparison before the update.
I know this may be everything wrong, but if it helped me, maybe it could help some others I need :)
I think that the setvar func was a good idea I had :)
As I said I'm always opened to suggestions because I want to learn from the experts!
 
Last edited:
For those like me who are behind a double NAT situation, where a wan IP change isn't detected by the native updater...


That was the problem I had and that's why I've written this
The "external" option for getting the IP should work in this case
 
The "external" option for getting the IP should work in this case
Yes, but for some reason it only trigger like once a day - in my case my isp updates my IP sometimes 4 times per day. Sometimes more, sometimes less.

Before I came up with this script I tested the external option many times and no success. I had to create it.

So... It should, but it doesn't.
 
Thanks! Just made the change
@maghuro you clutter up the /jffs/configs folder with an file that does not belong there.
Move settings for /jffs/scripts/ scripts to the /jffs/addons/<your addon name> folder.
What does the ".d" means on script folder name? As in "dnsomatic.d" inside configs folder.
I replicated the ".d" from all other scripts, without knowing what does it mean :p
 
What does the ".d" means on script folder name? As in "dnsomatic.d" inside configs folder.
I replicated the ".d" from all other scripts, without knowing what does it mean :p
Don't bother, it's an old habit of some. The .d signifies a directory with config files.
I only use it in Diversion, for a Dnsmasq conf file.
Just use plain simple folder names, if you must. Else put them in the root folder of your addon folder, see amtm's folder.

I have one subfolder there, but that's because I had to differentiate between the standard and firmware amtm installation. And that was the simplest way.
 
To add to the above. In *NIX systems, a folder or a file are essentially the same from the OS's viewpoint. Hence the .d was used to make it visually clear.
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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