Last active
December 5, 2015 09:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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