Using DynDNS for iPhone OS 3.0 without crontab but with launchd

Apple iPhone OS 3.0 does not have crontab anymore. You are supposed to use launchd's facilities to execute something at a scheduled interval. Here is an example of a simple script to update the IP-address at DynDNS.org.

The script /var/mobile/update-dyndns.org contains:

#!/bin/sh

host="your-host-name.dyndns.org"
user="your-username"
pass="your-password"

oldip=$(cat /tmp/ip)
wget -o /dev/null -O - http://ip.serverchief.com/ > /tmp/ip
ip=$(cat /tmp/ip)

if [ "$oldip" != "$ip" ] ; then
echo -n "$(date) "
echo $(/usr/local/bin/wget -O - "http://$user:$pass@members.dyndns.org/nic/update?hostname=$host&wildcard=NOCHG&bacakmx=NOCHG"  2> /dev/null)
fi

The file /var/LaunchDaemons/org.dyndns.update.plist contains:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict> 
<key>Label</key>
<string>org.dyndns.update</string>
<key>ProgramArguments</key>
<array>
<string>~/mobile/dyndns-update.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict> 
<key>Minute</key>
<integer>3</integer>
</dict>
</dict>
</plist>

And execute:

# launchctl load org.dyndns.update.plist

Now your IP will be update every 3-rd minute. Have fun!

About Consultancy Articles Contact




References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning robert@meinit.nl