Skip to content

Instantly share code, notes, and snippets.

@Sketches-su
Created July 9, 2015 07:45
Show Gist options
  • Save Sketches-su/33ff9704556b6c90ae35 to your computer and use it in GitHub Desktop.
Save Sketches-su/33ff9704556b6c90ae35 to your computer and use it in GitHub Desktop.
Shell script for mounting remote dir by sshfs and obtaining SSH console
#!/bin/bash
if [ -z "$1" ]; then
echo No user@host specified!
exit 1
fi
if [[ ! "$1" =~ ^[^@:]+@[^@:]+:[^@:]+$ ]]; then
echo Invalid user@host!
exit 2
fi
mntdir="$HOME/remote/`echo "$1" | cut -d':' -f1 | sed -e 's#@#.at.#'`"
if [ `cat /etc/mtab | grep "$mntdir" | wc -l` -gt 0 ]; then
echo Point is already mounted!
exit 3
fi
[ ! -d "$mntdir" ] && mkdir "$mntdir"
sshfs "$1" "$mntdir"
ssh "`echo "$1" | cut -d':' -f1`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment