OSX – run a script during boot

I’ve been running OSX for a while, and one of my favorite things about it is having Unix underneath that gorgeous GUI interface. However, OSX does so many things different from “standard” (Linux, Solaris, BSD, etc) Unix that I often find myself struggling to figure out how to do things in OSX vs standard Unix procedures.

Here’s one circumstance – I’m running a headless Mac Mini server in a large DHCP network, and if I have to reboot the server for any reason, there’s no guarantee that I will get the same IP address again (especially if the server was powered down for any appreciable amount of time). Now I could crawl under the desk and switch the DVI adaptor to the Mac (after putting on the DVI-HDMI adaptor) but that just sucks.

It would be better if the server just emailed me the new IP address when it was booted so I know where to SSH/VNC to.

Unfortunately, the boot process for OSX is completely proprietary and involves StartupDaemons, plists and all sorts of crap – no rc.* scripts in sight. [actually,  Solaris (since 10) uses something similar called SMF – service management facility – which I also hate.. but at least it still uses rc.* scripts as well]

Anyway, I was almost resigned to writing a new plist when I ran across a very handy bit of information – OSX uses Vixie cron, which has some special meta tags including a ‘@reboot’ tag that will execute upon boot:

@reboot /path/to/ipnotify.sh

Ultra simple, and works great! Now the server emails me its IP address after it has completed the boot process, saving me having to crawl around under the desk.