Thanks works perfect for me.
rob
[HOWTO] DNS-O-MATIC Script / Update process
-
- New here
- Posts: 5
- Joined: Sat Apr 10, 2010 9:03 am
-
- New here
- Posts: 9
- Joined: Sun Apr 04, 2010 3:23 am
Re: [HOWTO] DNS-O-MATIC Script / Update process
I found this forum really very handy and I wanted to return something to the community.
I wrote a script to update openDNS from my QNAP TS 119 before I saw this post. Given a slightly different approach I thought I'd just share what I did.
So, for a QNAP TS-119 with version 3.3.7 (I tried 3.8.0 to 3.8.3 but found them way too buggy so back to this version which seems 'better').
This script will allow for OpenDNS (and DynDNS) to be updated on a regular basis. The solution allows for the disks to remain spun down.
Firstly I login to my NAS using:
and I issue the command so things like 'vi' work.
Then I mounted the RAM drive
and changed to that directory
I then created a file called autorun.sh which contained the following:
Then we need to make the script executable with
and the umount the RAM drive so the changes are remembered on each reboot with
Then I changed directory with
and created a file called 'update_dns_o_matic.sh' with the content:
then I made that file executable with
You will need to edit the script and replace with your username and password for DNS_O_Matic.
At this point you could test the script by calling and you should see a system log entry with the administration web interface of the NAS.
If you call and you should not see a log entry, well as long as it worked ok!
Now we just need to call the script on a regular basis using the in build linux scheduler, cron.
edit the file
and add the following to the end of that file
The '30 *' at the beginning will mean the script is called every hour at 30 minutes past the hour. You could change the number 30 for another number between 0 and 59 (for 0 minutes to 59 minutes past each hour).
Because the command line argument no_log_if_good is passed a system log entry is not made, and this means the disks do not need to spin up.
This script works well for me, and this disks don't spin up at all.
Hope you find it handy.
The last thing you need to do is reboot your server! Check the system log after reboot contains the one entry, and the system log should be silent after that, unless there's a problem.
On reboot the crontab file edited earlier will be reloaded. If you want to force a reload of the crontab then you'll need to
I wrote a script to update openDNS from my QNAP TS 119 before I saw this post. Given a slightly different approach I thought I'd just share what I did.
So, for a QNAP TS-119 with version 3.3.7 (I tried 3.8.0 to 3.8.3 but found them way too buggy so back to this version which seems 'better').
This script will allow for OpenDNS (and DynDNS) to be updated on a regular basis. The solution allows for the disks to remain spun down.
Firstly I login to my NAS using:
Code: Select all
telnet 192.168.1.2 13131
Code: Select all
export TERM=xterm
Then I mounted the RAM drive
Code: Select all
mount /dev/mtdblock5 /tmp/config/
Code: Select all
cd /tmp/config/
Code: Select all
#!/bin/sh
#this gets called when the system starts up
#
# copy a script into the root user folder on startup.
# the root user folder is wiped on each reboot
# the root user folder is part of the RAM drive and so using it doesn't spin up the disks, which is rather handy
cp /share/HDA_DATA/myroot/update_dns_o_matic.sh /root
# then call the script with no command line arguments. With no arguments an entry in the event logs will be created.
/root/update_dns_o_matic.sh &
Code: Select all
chmod +x ./autorun.sh
Code: Select all
cd ..
umount /tmp/config/
Code: Select all
cd /share/HDA_DATA/myroot
Code: Select all
#!/bin/sh
# script to update DNS-O-Matic.
# if the command line argument is no_log_if_good, then no system log entry will be written if the response
# from DNS-O-Matic is a good one.
# with no system log entry being generated the disks do not need to spin up.
write_log=$1
myusername=ENTER_HERE_YOUR_USERNAME_FOR_DNS_O_MATIC
mypassword=ENTER_HERE_YOUR_PASSWORD_FOR_DNS_O_MATIC
cd /root
if [ -f ./update ]
then
# a file called update already exists which is not expected
rm ./update
/sbin/write_log "DNS-O-Matic update script previously failed. 'update' file remained." 2
fi
# call DNS-O-Matic using wget
if /usr/bin/wget --no-check-certificate --quiet https://$myusername:$mypassword@updates.dnsomatic.com/nic/update
# wget creates a file called update containing the response made
then
# the call was a valid one
logentry=$(echo -n 'DNS-O-Matic update response was ';cat update)
response=$(awk -F " " '{print $1}' update)
# response contains the first word of the update response, typically 'good'
if [ "$response" != "good" -o "$write_log" != "no_log_if_good" ]
then
# the response is either not good OR the command line argument was not no_log_if_good
if [ "$response" = "good" ]
then
# response was good, writing a log entry with '4' information
/sbin/write_log "$logentry" 4
else
# response was not good, writing a log entry with '2' warning
/sbin/write_log "$logentry" 2
fi
fi
rm update
else
/sbin/write_log "DNS-O-Matic update failed. Link down or wrong username/password" 2
exit 1
fi
exit 0
Code: Select all
chmod +x ./update_dns_o_matic.sh
At this point you could test the script by calling
Code: Select all
/root/update_dns_o_matic.sh
If you call
Code: Select all
/root/update_dns_o_matic.sh no_log_if_good
Now we just need to call the script on a regular basis using the in build linux scheduler, cron.
edit the file
Code: Select all
vi /etc/config/crontab
Code: Select all
30 * * * * /root/update_dns_o_matic.sh no_log_if_good
Because the command line argument no_log_if_good is passed a system log entry is not made, and this means the disks do not need to spin up.
This script works well for me, and this disks don't spin up at all.
Hope you find it handy.
The last thing you need to do is reboot your server! Check the system log after reboot contains the one entry, and the system log should be silent after that, unless there's a problem.
On reboot the crontab file edited earlier will be reloaded. If you want to force a reload of the crontab then you'll need to
Code: Select all
crontab /etc/config/crontab
/etc/init.d/crond.sh restart
-
- New here
- Posts: 2
- Joined: Sat Dec 26, 2009 7:02 pm
Re: [HOWTO] DNS-O-MATIC Script / Update process
Hi, nice script. Thanks for sharing!matthewpetershaw wrote: ...and created a file called 'update_dns_o_matic.sh' with the content:
Code: Select all
... # call DNS-O-Matic using wget if /usr/bin/wget --no-check-certificate --quiet https://$myusername:$mypassword@updates.dnsomatic.com/nic/update ...
Works well for me, after I changed the above WGET-line cause of an AT-sign in my username:
Code: Select all
...
# call DNS-O-Matic using wget
if /usr/bin/wget --no-check-certificate --quiet --http-user=$myusername --http-password=$mypassword https://updates.dnsomatic.com/nic/update
...
-
- New here
- Posts: 3
- Joined: Mon May 21, 2012 1:41 am
Re: [HOWTO] DNS-O-MATIC Script / Update process
I'm having an issue with the script and I'm hoping someone might be able to tell me what's going on. I tweaked the script per @acmor suggestion since my username also has an "@" sign in it to read as follows (note: username and password xxxxx'ed out):
#!/bin/sh
# script to update DNS-O-Matic.
# if the command line argument is no_log_if_good, then no system log entry will be written if the response
# from DNS-O-Matic is a good one.
# with no system log entry being generated the disks do not need to spin up.
write_log=$1
eyusername=xxxxx@xxxx.com
mypassword=xxxxxxxx
cd /root
if [ -f ./update ]
then
# a file called update already exists which is not expected
rm ./update
/sbin/write_log "DNS-O-Matic update script previously failed. 'update' file remained." 2
fi
# call DNS-O-Matic using wget
if /usr/bin/wget --no-check-certificate --quiet --http-user=$myusername --http-password=$mypassword https://updates.dnsomatic.com/nic/update
# wget creates a file called update containing the response made
then
# the call was a valid one
logentry=$(echo -n 'DNS-O-Matic update response was ';cat update)
response=$(awk -F " " '{print $1}' update)
# response contains the first word of the update response, typically 'good'
if [ "$response" != "good" -o "$write_log" != "no_log_if_good" ]
then
# the response is either not good OR the command line argument was not no_log_if_good
if [ "$response" = "good" ]
then
# response was good, writing a log entry with '4' information
/sbin/write_log "$logentry" 4
else
# response was not good, writing a log entry with '2' warning
/sbin/write_log "$logentry" 2
fi
fi
rm update
else
/sbin/write_log "DNS-O-Matic update failed. Link down or wrong username/password" 2
exit 1
fi
exit 0
However, when I run this I get the following error. Is this as simple syntax error? I'm a bit of a Linux n00b.
[~] # ./update_dns_o_matic.sh
./update_dns_o_matic.sh: line 40: : command not found
./update_dns_o_matic.sh: line 41: : command not found
#!/bin/sh
# script to update DNS-O-Matic.
# if the command line argument is no_log_if_good, then no system log entry will be written if the response
# from DNS-O-Matic is a good one.
# with no system log entry being generated the disks do not need to spin up.
write_log=$1
eyusername=xxxxx@xxxx.com
mypassword=xxxxxxxx
cd /root
if [ -f ./update ]
then
# a file called update already exists which is not expected
rm ./update
/sbin/write_log "DNS-O-Matic update script previously failed. 'update' file remained." 2
fi
# call DNS-O-Matic using wget
if /usr/bin/wget --no-check-certificate --quiet --http-user=$myusername --http-password=$mypassword https://updates.dnsomatic.com/nic/update
# wget creates a file called update containing the response made
then
# the call was a valid one
logentry=$(echo -n 'DNS-O-Matic update response was ';cat update)
response=$(awk -F " " '{print $1}' update)
# response contains the first word of the update response, typically 'good'
if [ "$response" != "good" -o "$write_log" != "no_log_if_good" ]
then
# the response is either not good OR the command line argument was not no_log_if_good
if [ "$response" = "good" ]
then
# response was good, writing a log entry with '4' information
/sbin/write_log "$logentry" 4
else
# response was not good, writing a log entry with '2' warning
/sbin/write_log "$logentry" 2
fi
fi
rm update
else
/sbin/write_log "DNS-O-Matic update failed. Link down or wrong username/password" 2
exit 1
fi
exit 0
However, when I run this I get the following error. Is this as simple syntax error? I'm a bit of a Linux n00b.
[~] # ./update_dns_o_matic.sh
./update_dns_o_matic.sh: line 40: : command not found
./update_dns_o_matic.sh: line 41: : command not found