The challenge: keeping my IP address up to date
I recently wanted to find a way to keep dynamic DNS updated for a smart DNS service at home (to keep MOG, Pandora and LastFM running without using the hassle of a VPN). It turns out my home DSL router’s IP address changes all the time and I was updating my DNS mapping service multiple times per day.
It was a bit of a hunt to find a suitable dynamic DNS solution as dyndys.org went (expensive) paid at $25/year recently. After looking at some of the competitors, I finally chose DNSmadeeasy to avoid creating managing more logins. We already have work accounts and DNSmadeeasy includes dynamic DNS with every name in your account (fabulous value if you need a lot of dynamic DNS). If you are looking for free dynamic DNS, the amusingly named http://afraid.org appears to be the last good free solution operating.
While on Afraid.org’s site, I found a nice quick Bash script which could be customised for DNSmadeasy. Unfortunately I couldn’t get Curl to work well in bash, with DNSmadeeasy’s update command failing (personal data removed) even with -d data variables or with a simple http command:
I was able to find a Perl script for DNSmadeeasy. The DME Update scrip I was able to customise (yes, unlike wget Perl is included in Mac OS X 10.6.8 (you can check for Perl with a quick “perl -v”: I got v.5.10.0 back). Troubleshooting was a cinch once I enabled the “-f -v” flags for forcing an update and for verbose feedback.
Once I finally had a working update script the next question was how to make it run repeatedly to keep with the constantly changing IP. There are three good choices on OS X, either a cron job, LaunchD or a dedicated application.
LaunchD: Lingon + launched.zerowidth.com
LaunchD is what Apple recommends. If that’s the path you want to follow, setting up one of these plists by hand is like a trip to the dentist. There’s two solutions. Lingon which has a watered down version in the app store or a full fledged version at the Peter Borg’s site. Whatever you do, don’t choose the app store version, it’s crippled. What’s obnoxious is Borg charges more for the non-app store version (even though he’s not paying Apple a cut). You can actually get the old free version (which is apparently compatible with 10.7 and 10.8 and definitely worked on 10.6.8) back on SourceForge.
Even more fun than Lingon if you are creating new LaunchD plists is ZeroWidth’s Launched online service. Here you just, fill in the name, your command, set up your schedule and press “Create .plist”. What happens on the other side is even more amazing.
You get three options for install.
- A quick command line version.
- The .plist itself with options to edit and/or download.
- Manual command line.
Launched is one of the best web services I’ve ever seen and a model for the genre. If everyone would write web applications like Nathan Witmer, the world would be a better place.
Crons can be edited by hand. Unotelly has a pretty good tutorial here.
- Open Terminal
- Type “crontab -e”
- Press “i” to enter insert mode.
- Write or paste in your Cron, something like: “* 1 * * * curl -o /dev/null http://www.unotelly.com/unodns/auto_auth/hash_update/updateip.php?user_hash=YOUR_HASH_HERE”
- Press “Esc”
- Type “:wq” to save
Frankly, editing cron from the command line is a bit fiddly. Fortunately, there’s a very sexy OS X application called Cronnix from Sven Schmidt.
Unfortunately there’s only a very lean Google Code site there. What’s very cool about Cronnix is you only need to run it when you want to edit your crons. Bad Apple for slowly deprecating the industry standard crons. Apparently even Apple is not presumptuous enough yet to remove cron from Unix, though they would like to.
cronnix gui schedule
Dedicated Application: Scheduler
Finally, there’s an ultra flexible dedicated application that almost no one has heard of but which is incredibly flexible and powerful called simply Scheduler which is on version 6 and has only been downloaded 19,469 times. Unbelievably Scheduler is free. Why would anyone want a dedicated application for repeated programs when both Cron and launchD are built in to OS X. Author Joao Varela explains:
Scheduler goes far beyond cron and launchd in several aways, as it has built-in functions for posting reminders together with your favorite music (including iTunes songs), launch and open web pages and download files with your favorite browser, among may other features and options. Moreover, Scheduler has many, many scheduling options that are very difficult to do with launchd or cron, such as with a few clicks you can schedule a script to be launched every 2 minutes on the last Monday of the month of June, but not in July, and so and on.
There’s versions that work as far back as 10.2 with wide compatibility between major revisions. How Varela manages to maintain this application as freeware is miraculous to me. All he gets out of his users is an email address. If you are totally uncomfortable with command line type tools or have very complex scheduling needs, Scheduler is a fantastic application.
The solution I’ve chosen for myself is Cronnix and Cron. Cron is an open source technology which works on both desktop and server Linux and Unix. Regardless of what foolishness Apple comes up with next, skills in working with Cron will help me work on my servers and my own computers. LaunchD skills are only guaranteed to be worth something as far as Apple’s next OS update (Apple has hidden all the Library and System folders in recent updates, xCode won’t output Snow Leopard compatible applications and Apple Script has been deprecated, Apple are more than capable of throwing LaunchD overboard at the most inconvenient moment).
Alec has been helping businesses succeed online since 2000. Alec is an SEM expert with a background in advertising, as a former Head of Television for Grey Moscow and Senior Television Producer for Bates, Saatchi and Saatchi Russia.