Skip to content

Instantly share code, notes, and snippets.

@AndiH
Created Oct 28, 2013
Embed
What would you like to do?
sshvol – Commandline-mounts a remote ssh volume. Got that from some one who got that from some one who…
#! /bin/bash
# fast mount of home at remote server by its name or alias in .ssh/config
# usage: autosshfs <server-name> (without trailing : or path)
SERVER=$1
MOUNT_DIR=/Volumes
if [[ -z $SERVER ]]; then
echo "usage: sshvol <server-name>[:<server_path>]"
exit 1
fi
LOCAL_PATH=`echo -n $SERVER | tr -d ':' | tr '/' '-'`
if [ `expr $SERVER : '.*:'` == 0 ]; then
# short path
SERVER_PATH=$SERVER:
else
# full path
SERVER_PATH=$SERVER
fi
MOUNT_POINT=$MOUNT_DIR/$LOCAL_PATH
if [[ -e $MOUNT_POINT ]]; then
if [[ ! -d $MOUNT_POINT ]]; then
echo "file $MOUNT_POINT exists and is not a directory"
exit 1
fi
# elif [[ {mount | grep -q $MOUNT_POINT} ]]; then
# echo "something is already mounted on $MOUNT_POINT"
# exit 1
# fi
else
mkdir $MOUNT_POINT || (echo "cannot create directory $MOUNT_POINT"; exit 1)
fi
sshfs $SERVER_PATH $MOUNT_POINT -o volname=$SERVER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment