Skip to content

Instantly share code, notes, and snippets.

@JohnMurray
Created July 15, 2013 03:35
Show Gist options
  • Save JohnMurray/5997323 to your computer and use it in GitHub Desktop.
Save JohnMurray/5997323 to your computer and use it in GitHub Desktop.
A simple utility script for mounting a bunch of remote hosts over sshfs. Useful if you develop on 1 or more remote machines on a regular basis.
#!/usr/bin/env python
from subprocess import call
import os
servers = [
{
'host': 'some.remote.host', # host to connect to
'dir' : '/usr/local/supersecret/' # remote dir to mount
},
{
'host': 'some.other.remote.host',
'dir' : '/home/USER/'
}
]
user = os.environ['USER']
def connect():
"""
Connect SSH-FS's
"""
for server in servers:
try:
print("connecting to %s" %(server['host']))
print("------------------------------")
call(["sudo", "mkdir", "-p", "/Volumes/%s" % (server['host'])])
call(["sudo", "chown", "-R", user, "/Volumes/%s" % (server['host'])])
status = call(["sshfs",
"%s:%s" % (server['host'], server['dir']),
"/Volumes/%s" %(server['host'])])
if status == 0:
print("connected")
print("mounted locally at /Volumes/%s" % (server['host']))
print("mounted remotely at %s" % (server['dir']))
except:
print "Unexpected error:", sys.exc_info()[0]
finally:
print("\n")
def get_sudo():
call(["echo", "Running as root. Beware!! (mwahahahaha)"])
call(["sudo", "echo"])
get_sudo()
connect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment