Tiny Deathstars of Foulness

Yesterday I posted about Randomizing the Software Update Server for Mac OS X. I posted the script, which I called at But, what if you wanted to update the Software Update Server list in the script automatically using your own URL (ie – on a timed interval)? In this case, you could simply use the following script, which pulls a new copy of the script from the site:
#!/bin/bash URL=”” PATH=”/Scripts/” /usr/bin/curl $URL > $PATH exit 0
Notice that I made the URL and PATH variables. This is really just to make it easier to use if others choose to do so. It would also be pretty easy to add a line at the end to run the script; therefore, it would download the latest copy of the script and then run it. This can also be used as a vehicle for running a number of scripts, pushing out timed updates without ARD (or another similar software package) or just setting a nightly event to look for changes to something and then run it, a process we’ll call mutex checking, for future reference.

April 21st, 2009

Posted In: Mac OS X, Mac OS X Server, Mac Security, Mass Deployment, Ubuntu, Unix

Tags: , , ,

I’ve had a few instances where there was no way to setup round robin DNS or a load balancer and we were looking to alternate between a bunch of software update servers.  In order to do so, I’ve written a quick shell script to do so.  Here it is, in pieces, so it makes sense. The following is a quick script to pull a URL from a random list of servers:
#!/bin/bash Sus=”″ sus=($Sus) num_sus=${#sus[*]} echo -n ${sus[$((RANDOM%num_sus))]} exit 0
This script would simply write to the screen one of the software update servers that we’ve loaded up into an array called sus, chosen using the $RANDOM function.  You can replace the servers in this array with your own and it will simply write to the screen which server it has chosen.  Now to have it actually set the server, replace the line that begins with echo -n with the following line:
defaults write /Library/Preferences/ CatalogURL ${sus[$((RANDOM%num_sus))]}
For deployment we’ve handled this two different ways.  The first is to have this script run at startup as a login hook (it’s really quick since it doesn’t do much) and let the OS run software updates based on whatever schedule you’ve employed.  The second is to set software updates to only ever run manually and then add a line at the end of the script to run them, which allows you to schedule the task using launchd or run it manually over ARD.  To set the software udpates to run manually, run this command on the target system once (it will persist):
softwareupdate –schedule off
Now, after the script chooses a random software update server, tell it to install all available software updates from that server each time it’s run by adding the following to the end of the script:
softwareupdate -i -a
There is a lot more logic that can be built into it, but this is the basics of assigning a random software update server using a shell script.

April 20th, 2009

Posted In: Mac OS X, Mac OS X Server, Mac Security, Mass Deployment

Tags: , , , ,