Skip to content

Instantly share code, notes, and snippets.

@mhluska
Last active December 17, 2015 20:39
Show Gist options
  • Save mhluska/5669349 to your computer and use it in GitHub Desktop.
Save mhluska/5669349 to your computer and use it in GitHub Desktop.
Unmount and spin-down a drive.
#!/bin/bash
DRIVE_NAME=${1:-Backup}
if [ -z "${DRIVE_NAME}" ]; then
echo 'No drive found.' 1>&2
exit 1
fi
drive_dir="$(mount -l | grep "\[${DRIVE_NAME}\]" | awk '{print $1}')"
drive_dir_no_num=$(echo ${drive_dir} | sed -E 's,/dev/([a-z]*).*,/dev/\1,g')
# Unmounts and spins down an external drive.
udisks --unmount ${drive_dir}
udisks --detach ${drive_dir_no_num}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment