#!/bin/bash # You will likely want to install this in /etc/periodic/daily (or weekly) so that it runs automatically # You will probably want to pair this with an email sending program of some sort. # Enabling postfix on OSX is kind of a pain, so you may want a self-contained mailer # like the "mailtest" utility here: http://mikehardy.net/mailtest # This script is currently written to expect that to be installed in /usr/local/bin HOME=/var/tmp/launchd ERROR_ADDRESS=example@example.com # You can find this out by saying "dig mx " MAILHOST=alt1.aspmx.l.google.com PORT=/opt/local/bin/port # This script suffers from the "thundering herd" problem - the server is too # stressed to respond because lots of nightly scripts like this one are hitting it # Lets be nice and definitely sleep 10 minutes, then sleep 0-15 more minutes after that sleep 600 sleep $(( $$ % 900 )) # Update ourselves and all the port files, output goes to /var/log/weekly.out # if the script is in /etc/periodic/weekly/ $PORT selfupdate # Make sure that worked if [ $? != 0 ]; then /usr/local/bin/mailtest -s "Unable to check for outdated ports" -m "empty" -f root -H $MAILHOST -t $ERROR_ADDRESS exit 1 fi # Get the list of ports output=`/opt/local/bin/port list outdated` output_count=`echo $output | wc -l` if [ $output_count -ne 1 ]; then /usr/local/bin/mailtest -s "There are outdated ports" -m "$output" -f root -H $MAILHOST -t $ERROR_ADDRESS fi