Code request: sh script commands & syntax

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
cdkiller
DD-WRT User


Joined: 26 Jun 2007
Posts: 262
Location: Trinidad & Tobago

PostPosted: Thu Aug 07, 2008 7:48    Post subject: INADYN scripts for multiple DDNS Reply with quote
Thanks a million for that explanation, you have thought me many things there. I think I will practice a bit and get this working.

Update 1:
I think I have it working now. I have tested it and I found no flaws yet, I hope that means it will work for everyone. These are the startup scripts to use if you want to update specific networks (aliases) in dnsomatic server. In these example I have two --alias entries but you can use any number you need. I had to revise the code several times to get it working properly but still you should check to make sure it works on your router else you may have to adjust the sleep and killall parameters.


.rc_startup Buffalo (uses AOSS and Bridge LEDs)
-----------------------------------------------

Code:
#!/bin/sh
mount ramfs /mmc -t ramfs
mkdir /mmc/etc
mkdir /mmc/etc/config
echo "#!/bin/sh
gpio disable 6
inadyn --background --username ??? --password ??? --alias ??? --alias ??? --dyndns_server_name updates.dnsomatic.com --dyndns_server_url /nic/update? --wildcard
sleep 2
gpio enable 6
gpio disable 1
sleep 2
killall -9 -w inadyn
gpio enable 1
" > /mmc/etc/config/ppp0.wanup
chmod 700 /mmc/etc/config/ppp0.wanup


I realized that a reboot results in the ppp0.wanup script running at most 5 times within a very short period and some are multiple instances so they overlap, I don't know what triggers it but I know that it used to update the dnsomatic 3 times at each change of ip, (maybe the first 2 runs didn't have a real wan ip to report, I am not sure). I managed to fix the 3 updates by adding the -w switch to the killall statement. I realized that if it runs 3 times then inadyn will run in 3 different instances so luckily the -w switch would leave killall in memory and kill all instances of inadyn even if it reappears. The second killall line is commented because it is not always necessary unless you use multiple --alias then you could use the second killall. It really needs to be tested and tweaked on each router because it depends on timing and all cpu are not the same. I could live with this, even though it may run the ppp0.wanup script 5 times now inadyn only gets a chance to work 1 time so it does not spam the server with 3 updates.

Look at my log below from the server, see the first 2 runs below updates the server 3 times but after I put in the -w switch to killall, you can see the top 2 entries only updated 1 time which is good. Adding the -w switch to killall fixed the multiple updates but it failed to kill the process, I fixed that by adding the -9 switch which is the same as -s KILL to send the KILL signal instead of the default TERM. For some reason -s KILL did not work but the numeric equivalent -9 works.
Quote:
OpenDNS details:
History

190.59.85.104, Aug 7, 2008 10:32 pm, OK
190.59.64.15, Aug 7, 2008 10:26 pm, OK
190.59.95.210, Aug 7, 2008 10:19 pm, OK
190.59.95.210, Aug 7, 2008 10:19 pm, OK
190.59.95.210, Aug 7, 2008 10:19 pm, OK
190.59.92.195, Aug 7, 2008 7:39 pm, OK
190.59.92.195, Aug 7, 2008 7:39 pm, OK
190.59.92.195, Aug 7, 2008 7:39 pm, OK


Update 2:
Here is working code for Linksys routers.

.rc_startup Linksys (using Security LEDs)
-----------------------------------------

Code:

#!/bin/sh
mount ramfs /mmc -t ramfs
mkdir /mmc/etc
mkdir /mmc/etc/config
echo "#!/bin/sh
gpio disable 3
inadyn --background --username ??? --password ??? --alias ??? --alias ??? --dyndns_server_name updates.dnsomatic.com --dyndns_server_url /nic/update? --wildcard
sleep 2
gpio enable 3
gpio disable 5
sleep 2
killall -9 -w inadyn
gpio enable 5
" > /mmc/etc/config/ppp0.wanup
chmod 700 /mmc/etc/config/ppp0.wanup



Here is Generic code for any router.

.rc_startup Generic
---------------------
Code:

#!/bin/sh
mount ramfs /mmc -t ramfs
mkdir /mmc/etc
mkdir /mmc/etc/config
echo "#!/bin/sh
inadyn --background --username ??? --password ??? --alias ??? --alias ??? --dyndns_server_name updates.dnsomatic.com --dyndns_server_url /nic/update? --wildcard
sleep 3
killall -9 -w inadyn
" > /mmc/etc/config/ppp0.wanup
chmod 700 /mmc/etc/config/ppp0.wanup



Update 3:
Here is code that can be used if you wish to use "force_update_period" etc. (Taken from initial posts above).

.rc_startup Generic non wanup
(inadyn always running in memory)
----------------------------------
Code:
#!/bin/sh
while [ "`ifconfig | grep -c ppp0`" = "0" ]; do
sleep 5
done   
inadyn --background --username ??? --password ??? --alias ??? --dyndns_server_name updates.dnsomatic.com --dyndns_server_url /nic/update? --update_period_sec 120 --forced_update_period 86400 --wildcard



Only add the --wildcard option if you actually use it.
If anything else comes to mind I will update these scripts, as for now they work.
All code in ths post is working, use the one you prefer.
Last Edited: Wed 13th August 2008.
cdkiller

_________________
[everything is to be replicate]


Last edited by cdkiller on Wed Aug 13, 2008 9:34; edited 3 times in total
Sponsor
eric1328
DD-WRT Novice


Joined: 19 Jul 2006
Posts: 9

PostPosted: Sat Aug 09, 2008 13:57    Post subject: Reply with quote
cdkiller, thanks so much. Just have a few questions:

All i have to do is add that script to the Commands box and hit Save Startup?

When does this send updates to DNSOMatic? Just when the WAN IP changes?

Can i add something to make it also always update every so seconds? (to see if the script is working on my router, since my WAN IP takes forever to change)

Do i have to add the custom.sh script you mention in the Aug6 9:32am post?

_________________
- Thanks, Eric
cdkiller
DD-WRT User


Joined: 26 Jun 2007
Posts: 262
Location: Trinidad & Tobago

PostPosted: Sat Aug 09, 2008 14:23    Post subject: Reply with quote
eric1328 wrote:
cdkiller, thanks so much. Just have a few questions:

All i have to do is add that script to the Commands box and hit Save Startup?
Yes.

eric1328 wrote:
When does this send updates to DNSOMatic? Just when the WAN IP changes?
This wiki link will explain when the script runs, I used the .wanup extension.

eric1328 wrote:
Can i add something to make it also always update every so seconds? (to see if the script is working on my router, since my WAN IP takes forever to change)
I am not quite sure I understand what you mean, you could check the logs on the dnsomatic website to see if it works. I made the code to kill itself to free up memory after it does its job. If you want to run it at regular intervals the best way I can think of is to configure a cron job to run the script /mmc/etc/config/ppp0.wanup at the interval you need. You will have to research how to use cron, I never used it before. You could also put in gpio for your router to light up an LED so you know when it executes.

eric1328 wrote:
Do i have to add the custom.sh script you mention in the Aug6 9:32am post?
No, those initial posts were inefficient code to me. That code works but inadyn remains in memory always. Perhaps you could use it instead if you want it to force update every few mins, just set your parameters in the inadyn line of code. Only use 1 of the scripts at a time, you can use the first one if you don't mind it residing in memory all the time. The final code only stores the script in memory but the first one leaves inadyn in memory, it is just my opinion that the second one is better, I have no real proof which one uses less memory but for sure the second code uses less cpu because it does nothing until a wanup event whereas the first code inadyn is always running in the background.

I must warn you that too many updates per minute and dnsomatic will ban you for abuse, this is what I tried to avoid by making the script so it updates only once per IP change.

_________________
[everything is to be replicate]
mayday175
DD-WRT Novice


Joined: 11 Jan 2007
Posts: 23

PostPosted: Wed Aug 13, 2008 23:07    Post subject: Reply with quote
cdkiller wrote:
You will have to research how to use cron, I never used it before.

I've used this to check the up/down status of my VPN connection, by running a script I have made once every minute.
Code:
echo '* * * * * root /bin/sh /tmp/check-VPN.sh &' > /tmp/crontab
stopservice cron && startservice cron

For more info on cron (especially what each * means), see this wiki page and some of the pages it links to.
Azure
DD-WRT User


Joined: 29 Apr 2009
Posts: 92

PostPosted: Fri Feb 19, 2010 20:54    Post subject: Reply with quote
To bump this thread.

If I run the code for the Linksys router and fill in everything correctly, will DNSOMATIC only pick up my IP address when it actually changes?

Cause it says 'waiting for update' right now.
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum