Skip to content

Instantly share code, notes, and snippets.

@JemarJones
Last active December 5, 2015 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JemarJones/afdbf123caa468741fcd to your computer and use it in GitHub Desktop.
Save JemarJones/afdbf123caa468741fcd to your computer and use it in GitHub Desktop.
Bash script to wait for time machine backup to finish, unmount drive, and shutdown
#!/bin/bash
# Requesting sudo if we don't have it already
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
if [[ -z "$1" ]]; then
#Replace this with your default harddrive (list them all with "df -h")
hd="/Volumes/Harddrive";
else
hd=$1;
fi
while ( ps -acx | grep 'backupd$' ); do
echo "Still backing up";
#A minute before we check again
sleep 60;
done;
echo "done";
diskutil unmount "$hd";
#This loop shouldnt actually be needed but just to be safe..
while ( df -h | grep "$hd" ); do
echo "Still connected";
sleep 60;
done;
#Waits a minute to shutdown just in case
shutdown -h +1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment