Skip to content

Instantly share code, notes, and snippets.

@synaptiko
Last active December 11, 2015 06:18
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 synaptiko/4557863 to your computer and use it in GitHub Desktop.
Save synaptiko/4557863 to your computer and use it in GitHub Desktop.
Simple shell script for un/mounting over SSH. Usage: ./mount-sshf <USER> <SERVER> [kill] It uses xclip command to copy and run command "cd <MOUNTED_DIR>" directly in terminal.
#!/bin/sh
if [ $# -ge 2 ]; then
USER=$1
SERVER=$2
DIR=${MOUNT_SSHFS__ROOT_DIR:-/var/tmp/mount-sshfs}/$SERVER
# it's possible to use primary or clip
XCLIP_SEL_MODE=${MOUNT_SSHFS__XCLIP_SEL_MODE:-primary}
if [ -d $DIR ]; then
if [ $# -eq 3 -a "$3" = "kill" ]; then
killall -9 sshfs
fi
fusermount -u $DIR
if [ $? -eq 0 ]; then
rm -ri $DIR
echo "Unmounted from $DIR"
else
echo "For safety reason directory was not deleted"
fi
else
mkdir -p $DIR
sshfs $USER@$SERVER:/ $DIR
if [ $? -eq 0 ]; then
echo "cd $DIR" | xclip -sel $XCLIP_SEL_MODE
echo "Mounted to $DIR"
else
rm -r $DIR
echo "Error: connection to $USER@$SERVER failed"
fi
fi
else
echo "Usage: ./mount-sshfs <USER> <SERVER> [kill]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment