Skip to content

Instantly share code, notes, and snippets.

@nottsknight
Last active December 10, 2015 02:19
Show Gist options
  • Save nottsknight/4366797 to your computer and use it in GitHub Desktop.
Save nottsknight/4366797 to your computer and use it in GitHub Desktop.
Short script for UNIX users to automatically connect to a remote file system via the sshfs program. Needs to be configured with the address of the server (line 4), your preferred mount point (line 5), a directory you can guarantee will be present IFF the file system is mounted (line 10), and the path to your home directory on the remote server (…
#!/usr/bin/env bash
# Script to mount or unmount a remote filesystem via sshfs
SERVERNAME="user@host.name"
MOUNTPOINT="$HOME/cs-home"
if [[ ! -d "$MOUNTPOINT" ]]; then
mkdir $MOUNTPOINT
fi
if [[ -d "$MOUNTPOINT/Private" ]]; then
if [[ $PWD =~ /home/ianknight/cs-home.* ]]; then
echo "Cannot unmount while still inside cs-home..."
exit 1
else
fusermount -u $MOUNTPOINT
echo "Unmounted $SERVERNAME from $MOUNTPOINT."
exit 0
fi
else
sshfs -o idmap=user "$SERVERNAME:/your/home/dir" "$MOUNTPOINT"
echo "Mounted $SERVERNAME at $MOUNTPOINT."
exit 0
fi
@nottsknight
Copy link
Author

Converted from Python to BASH, since it makes much more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment