How do I unmount a drive with a script?
You don't need sudo to unmount a drive.

Use diskutil

The following command ejects the volume Backup:

diskutil eject /Volumes/Backup


This should do it, although (IIRC) you might want…

diskutil unmount /Volumes/Backup


…to make it easier to re-mount without having to physically disconnect/reconnect the drive.

Ejecting All Disks

If you want to make sure you have ejected all of your disks, you can try this:

osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'


Third Party Tool: Mountain

There is also Mountain which will automate this for you.

Third Party Tool: Keyboard Maestro

Above all other ideas, I would recommend Keyboard Maestro which can do all of these things on sleep, and remount your drive on wake, plus 1,000 other things.