Skip to content

Instantly share code, notes, and snippets.

@hongkongkiwi
Last active January 28, 2016 14:11
Show Gist options
  • Save hongkongkiwi/201c33277cd3068675e3 to your computer and use it in GitHub Desktop.
Save hongkongkiwi/201c33277cd3068675e3 to your computer and use it in GitHub Desktop.
A nice friendly script for mounting a remote linux directory on demand.
#!/bin/bash
VOLUME_NAME="LinuxServer"
REMOTE_USER=`whoami`
REMOTE_SERVER="xx.xx.xx.xx"
MOUNT_DIR="$HOME/$VOLUME_NAME"
REMOTE_DIR="/home/$REMOTE_USER"
SSH_KEY="$HOME/.ssh/id_rsa"
TIMEOUT=5
RESULT=`sshfs -o reconnect \
-o volname=${VOLUME_NAME},noappledouble,noapplexattr,compression=yes,cache=yes \
-o ConnectTimeout=$TIMEOUT \
-o IdentityFile="$SSH_KEY" \
"${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_DIR}" \
"$MOUNT_DIR" 2>&1`
if [[ $RESULT != "" ]]; then
if [[ $RESULT == "mount_osxfusefs: mount point /Users/andy/LinuxServer is itself on a OSXFUSE volume" ]]; then
echo "$VOLUME_NAME is already mounted at $MOUNT_DIR!"
exit 1
else
echo "$VOLUME_NAME failed to mount!"
echo "ERROR: $RESULT"
exit 255
fi
else
echo "$VOLUME_NAME successfully mounted"
cd "$MOUNT_DIR"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment