Execute command on remote server which is mounted via sshfs to open remote file on desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, sys | |
import subprocess | |
HOST_MOUNT_DIR = '\$HOME/ubuntu' | |
# get the ip of the host | |
host = os.environ['SSH_CLIENT'].split(' ')[0] | |
# get the path from $HOME to the file | |
file_path = os.path.relpath(os.path.abspath(sys.argv[1]), | |
os.path.expanduser('~')) | |
# get the path from to the file on the host filesystem | |
remote_path = os.path.join(HOST_MOUNT_DIR, file_path) | |
# we're going to use the default editor on the host | |
args = '/usr/bin/ssh %s "\$EDITOR %s"' % (host, remote_path) | |
print args | |
subprocess.Popen(args, shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment