Skip to content

Instantly share code, notes, and snippets.

@joshbeard
Last active October 24, 2020 03:08
Show Gist options
  • Save joshbeard/6073933 to your computer and use it in GitHub Desktop.
Save joshbeard/6073933 to your computer and use it in GitHub Desktop.
Bash script to mount a TimeMachine sparsebundle on a file server.
#!/bin/bash
HOST="mynas"
SHARE="my_home"
UNAME="jdoe"
PROTO="smb"
BUNDLE="TimeMachine/mycomputer.sparsebundle"
# mount_smbfs doesn't seem to work with passwords that have special characters
#printf "Mounting on ${HOST}...\n"
#expect <<EOF
#spawn mount_smbfs //${UNAME}@${HOST}/${SHARE} ${POINT}
#expect "Password for ${HOST}:"
#send "${PASS}\r"
#wait
#EOF
open ${PROTO}://${UNAME}@${HOST}/${SHARE}
i=0
while [ $i -lt 60 ]; do
if mount | grep -q "//${UNAME}@${HOST}/${SHARE}"; then
mpoint=$(mount|grep "//${UNAME}@${HOST}/${SHARE}"|awk '{print $3}')
printf "Attaching ${BUNDLE}...\n"
if [ -e "${mpoint}/${BUNDLE}" ]; then
hdiutil attach "${mpoint}/${BUNDLE}"
break
fi
else
sleep 1
((i++))
fi
done
printf "Done.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment