Skip to content

Instantly share code, notes, and snippets.

@alexstaravoitau
Last active February 24, 2017 17:41
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 alexstaravoitau/e7860838e769dfed835418b38d8e069c to your computer and use it in GitHub Desktop.
Save alexstaravoitau/e7860838e769dfed835418b38d8e069c to your computer and use it in GitHub Desktop.
Routines for SSH-ing to remote machine, mount its file system and attach to a persistent tmux session. Check out my post about building and configuring my remote machine: http://navoshta.com/meet-fenton/
#!/bin/bash
# Connects to remote server, mounts its file system or attaches to a tmux session.
USER="tom"
SERVER="$USER@10.23.45.67:8989"
LOCAL_KEY_PATH="/Users/tom/ssh_keys/key"
LOCAL_MOUNT_PATH="/Users/tom/mount/"
if [ $# -eq 0 ]; then
echo "Connecting to Fenton."
ssh $SERVER
fi
while test $# -gt 0; do
case "$1" in
jesus|-jesus|--jesus)
shift
if [ $1 == 'christ' ]; then
echo "FENTON! FENTON, JESUS CHRIST! FENTON!!!"
open 'https://www.youtube.com/watch?v=3GRSbr0EYYU'
fi
shift
;;
fs|-fs|--fs)
echo "Mounting Fenton file system."
umount $SERVER:/ &> /dev/null
sshfs -o delay_connect,reconnect,ServerAliveInterval=5,ServerAliveCountMax=3,allow_other,defer_permissions,IdentityFile=$LOCAL_KEY_PATH $SERVER:/ $LOCAL_MOUNT_PATH
shift
;;
jn|-jn|--jn)
echo "Attaching to Jupyter Notebook session on Fenton."
ssh -t $SERVER 'tmux -CC attach'
shift
;;
*)
break
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment