Carbon Copy Cloner shell script for ejecting the source drive I created a backup system for a friend, using Carbon Copy Cloner. The system has been up and running since January, but it needs regular intervention. 

The main problem is that external hard drives are not ejected before disconnecting. When plugged in, the system does not recognize them, and that's when I intervene and get it to recognize them again. 

By using CCC's "after run tasks" function, which gives you the option to ask it to unmount the destination drive after backing up, I've been able to solve half the problem. CCC is automatically mounting and unmounting the destination only as needed. So anytime the destination drive is removed, its always already ejected.

I'd like for this to work for some of the source drives as well.  Of course its not necessary for the laptop's main drive, but there are a number of external drives that are frequently used off site.  After they're used, I'd like them to back up at the end of the day, and then eject when they're done.

I've found CCC's shell script for ejecting the destination: 

source="$1"
dest="$2"
exitStatus=$3

####Inserted script to run only if backup successful (exitStatus=0)

if [ "$exitStatus" = "0" ]; then
    # foo
else
    # bar
fi

####Eject destination drive

devID=`diskutil info "$2" | awk '/Device Identifier/ {print $NF}'`
if [ "$devID" != "" ]; then
    (sleep $delay; diskutil unmountDisk "$devID"; diskutil eject "$devID") &amp;
else
    (sleep $delay; diskutil eject "$2"; if [ $? -ne 0 ]; then diskutil    unmountDisk "$2"; fi) &amp;
fi


I think this would work the same for the source drive, if I change it to:

source="$1"
dest="$2"
exitStatus=$3

if [ "$exitStatus" = "0" ]; then
    # foo
else
    # bar
fi

devID=`diskutil info "$1" | awk '/Device Identifier/ {print $NF}'`
if [ "$devID" != "" ]; then
    (sleep $delay; diskutil unmountDisk "$devID"; diskutil eject "$devID") &amp;
else
    (sleep $delay; diskutil eject "$1"; if [ $? -ne 0 ]; then diskutil    unmountDisk "$1"; fi) &amp;
fi


I'm not completely sure how this script works, so before I try this out, does anyone see a problem?
It's much simpler for the source, the following should be sufficient:

#!/bin/sh
diskutil eject "$1"


Mike