Testing for Power v2

A while back I presented a solution to a pretty icky problem - how to test for intermittent power issues. Here's a slightly improved version of that script. It keeps the machine on for 2 minutes before shutting down and also keeps an activity log. The delay is also used as the power on interval.

    if [[ $USER != "root" ]]; then
        echo "This must be run as root"
        exit 1
    fi

    ROOTPW="1234"
    DELAY=120
    LOGFILE=~/Desktop/poweron.command.log

    osascript -e "delay $DELAY"
    TIMESTAMP=$(php -r "echo date ('H:i:s"', time() + $DELAY);")
    echo $ROOTPW | sudo -S pmset repeat poweron MTWRFSU $TIMESTAMP
    echo -n $(date "+%d.%m.%y @ %H:%I:%S") >> $LOGFILE
    echo "      " $(wc -l $LOGFILE) >> $LOGFILE
    osascript -e "tell application "Finder" to shut down"
    exit 0
Comments (0)
PurpleSync

Here's a pretty neat little AppleScript (did I just say that?!) for backing up random bits of your home folder. Just flag anything with the Purple Label in the Finder and PurpleSync will pick it up and back it up to a destination of your choosing, which it will prompt for only once (delete the pref file to reset).

If you only have Apple's rsync (2.6.3), then this will unfortunately butcher the extended attributes (like the label) and ACLs, since it does not understand the -X and -A arguments. Version 3.0 from MacPorts works better.

I kinda like the idea that, instead of defining stuff that I don't want backed up (ala TimeMachine), I just label the ones I do. Labels are very easy to use and audit and don't require special software.

The script itself is a whopping 11 lines long:

set dst to ""
set homedir to POSIX path of (path to home folder)

try
    set dst to do shell script "defaults read " & homedir & "/Library/Preferences/com.firstpartysoftware.purplesync syncDestination"
on error
    set dst to quoted form of POSIX path of (choose folder)
    do shell script "defaults write " & homedir & "/Library/Preferences/com.firstpartysoftware.purplesync syncDestination " & dst
end try

do shell script "rsync -paz  --delete --exclude=" & dst & " $(mdfind -onlyin " & homedir & " kMDItemFSLabel=3) " & dst

Stick it into iCal to have it run automagically.

Comments (0)
makeuser

The inability to create user accounts from the command line is something that every Mac SA runs into at some point. Then we write our own scripts (here's mine, here's dre's, for example).

But then today I discovered this:

zulu-30:~ admin$ /Library/Receipts/RemoteDesktopClient.pkg/Contents/Resources/makeuser 
ERROR: You must be root to run this tool.
ERROR: --longname not provided.
ERROR: Flag --shortname not provided.

makeuser -r "<volume path>" [ -0  -v -h ] {other options}

General Options:
----------------
-h | --help                    : Print command help.
-v | --verbose                 : Verbose output.

Required Account Settings Options:
----------------------------------
-n | --longname       "<string>" : User long name.
-s | --shortname      "<string>" : User short name.

Optional Account Settings Options:
----------------------------------
-l | --loginpic      "<file>"   : Choose login picture.
-c | --cryptpassword "<string>" : Cryt password for this user.

The weird thing is there's different versions of this tool on the same OS X versions. The previous one was run on 10.4.11, as is the following:

flipbook:~ filipp$ /Library/Receipts/RemoteDesktopClient.pkg/Contents/Resources/makeuser
makeuser - scripted user creation under Mac OS X 10.2 or later
Usage:   makeuser -user <user> -realname <realname> [ -password <shadowpass> | -cryptpass <cryptpass> ] [<opts>]
....

10.5 behaves like the latter. Notice that this is all indeed inside the receipt package. :) While makeuser is far from being as nice as dre's adduser, most of the time, it's good enough.

Comments (0)
ddrescue AppleScript Applet

As said before, ddrescue is a really great data rescue utility. I've made a really simple AS application wrapper for it. Just name the applet, for example, "ddrescue-disk2s3", copy it on your backup drive, launch and give sudo your password.

It functions just like the shell snippet I, but contains the ddrescue binary so it's super easy to move around, also you don't have to edit any text files - just put the failing drive's /dev name in the app name.

Comments (0)
Restarting an Installation

I recently had to re-partition a 10.5 server just after the install had been done (the boot partition turned out too small). The server was completely headless at that point and I couldn't just resize the parts using diskutil because this was all on RAID 5.

There's an interesting "feature" in Server Assistant - the server will eject any optical media until you get to the serial number part. I tested this several times and the results were consistant. Anyways, you have to get to the serial number part, then insert the install DVD, then set that as the boot partition:

bless --folder /Volumes/Install Mac OS X Server --setBoot && reboot

After which you can just ARD to the box and re-partition and - install. This confused the heck out of me for a while - posting it here as a "warning". :-D

Comments (0)