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!
Comments
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>
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.
It means you will have to
It means you will have to open a terminal (the black screen) and type in those commands, followed by [RETURN]. This will execute that one line. (That is excluding the starting hash. (#))
do you think this could be
do you think this could be used to auto start an app after the ipod was just plugged to a power source?
i am trying to find a solution for some sort of auto start solution.
thanks, stephan.