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)
fiThe 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.plistNow 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 |
Comments
Here is my simple script and
Here is my simple script and launchd plist file:
dyndnsupd.sh:
#!/bin/sh
ip=`ifconfig pdp_ip0| grep inet | awk '{print $2}'`
if [ $ip ]
then
curl --insecure "https://userid:passwd@members.dyndns.org/nic/update?hostname=yourhostname.domain&myip=$ip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" 1> /dev/null 2> /dev/null
fi
*The curl line should be a single line.
org.dyndns.update.plist (in /System/Library/LaunchDaemons/)
<?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>/private/var/root/Scripts/dyndnsupd.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration/com.apple.network.identification.plist</string>
</array>
</dict>
</plist>
Its working fine on my iPad (1st Gen) and updates wheneven my 3G IP changes.
Tested the 3 minute config on
Tested the 3 minute config on iphone 3 and it did'nt appear to work
So I tested the WatchPaths config and it was updating about every 10 sec
so somethings not quite right.
Try: WatchPaths /Library/Pre
Try:
Everytime your IP changes (except when the IP gets dropped) the file:
"/Library/Preferences/SystemConfiguration/com.apple.network.identification.plist"
changes.
- Mark
Instead of running the script
Instead of running the script every three minutes when nothing has changed, why not use the WatchPaths key and only run on wake/sleep or a network state change:
<key>WatchPaths</key><array>
<string>/Library/Preferences/SystemConfiguration</string>
</array>
i would also suggest
i would also suggest using:
echo -n $(ipconfig getifaddr en0) > /tmp/ipinstead of:
wget -o /dev/null -O - http://ip.serverchief.com/ > /tmp/ipfor obtaining the phone's wifi ip address in the update script. ipconfig is faster, safer, and does not depend on any resources (e.g., a website) outside the phone itself.
So, does this work?
So, does this work? (WatchPaths instead of every 3 min?)
In my country you pay by traffic so if the connection could be avoided it would be better (plus you'd be saving battery life!)
So does this fail silently
So does this fail silently when there is no internet connection? i have an itouch that inst always connected to wireless, but i would like to set it up to interface with dyndns
Hi there.. I was wondering
Hi there..
I was wondering where requests for ip.serverchief.com come from, i get 100+ unique hits per day.. now it makes sense :)
I thought no-one will use this except me..
glad its being put to a good use. i will keep this portion up.
Regards
ServerChief
www.serverchief.com
From Apple's documentation
From Apple's documentation I'd have taken that "StartCalendarInterval Minute 3 "StartInterval 3 " for executing the script every three minutes. Unfortunately up to now neither way would run on my iphone, so I can't just try and tell. What's your actual experience: does the script execute every three minutes with the script given?
causes launchd to start the program at 01:03 a.m., 02:03 a.m. and so on, and that one would have to put it like "
Thanks
Carlo
Thanks for the script but I'm
Thanks for the script but I'm unsure what to do with the last step. What do you mean execute? I'm not very familiar with unix but it looks like a commented line.