Need help with shell script

digilink

Gawd
Joined
Jul 27, 2002
Messages
566
I run some websites at home and periodically my IP changes. I'm working on a shell script to run on cron that will check my IP every 12 hours and update it if needed.

I'll admit I'm not much of a programmer, but here is what I've come up with so far:

#!/bin/bash
publicip=`curl -s http://whatismyip.org/`
/root/ednsupdater -u username -p password -ip $publicip -d mydomain1.com
/root/ednsupdater -u username -p password -ip $publicip -d mydomain2.com
/root/ednsupdater -u username -p password -ip $publicip -d mydomain3.com

As you can see, I pull my public IP and assign it to a variable named $publicip and pass it on to another script which updates the DNS service I use.

What I would like to do is something like this, but I'm not sure of the syntax I would use:

if $public has changed, then execute the ednsupdater script, otherwise do nothing

I'd also like to add support to send me an email if it has changed, possibly even write something to syslog? I'm thinking some if then else statements would do what I need, but I'm not well versed enough to write them correctly.....
 
i know it's not pertinent to the question, but it may be pertinent to your purposes. i use noip.com


it's a dynamic dns service. it may be what you want to do.
 
You need to store your old IP address somewhere so that you can compare that to the new one to see if it changed since you last checked.

But I'm also wondering why don't just do this with a DDNS service? :confused:

Otherwise...

Code:
if [ "$newip" = "$oldip" ]; then
   # IP hasn't changed yet, so...
   do something
else
   # mail ?
   # log it?
   do something else
fi

If you want to mail, then that needs info like "what mail client agent can you use" and ISP stuff.

If you want to syslog it, check out logger (1).
 
But I'm also wondering why don't just do this with a DDNS service?

Well I run 3 TLD's and use name based hosting on Apache, I'm specifically using everydns.net, it's worked well and it's run by the same guy that founded OpenDNS.

The script I call (ednsupdater) does the IP update for me on their DNS servers....
 
Back
Top