Last active
August 6, 2018 03:46
-
-
Save why-not/aafedd4cc0cc67d52749d2a7d21a7798 to your computer and use it in GitHub Desktop.
When you have a Sublime Text SFTP remote folder mapping to an Amazon AWS machine, everytime you reboot you have to update your Sublime SFTP config file so it knows where the folder/files are now. This ofcourse is massively tragic and should not be permitted in a civilized society. Hence this script. It even prints a connection string, so you can…
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
import json | |
import subprocess | |
"""EDIT FNAME TO UPDATE WITH YOUR LOCAL FILE PATH""" | |
FNAME = "/PATH/To/SUBLIME/SFTP/FILE/sftp-config.json" | |
def update_json_file(given_ip, filename): | |
jsonfile = open(filename, "r") # open the json file for reading | |
data = json.load(jsonfile) # read the json into the buffer | |
jsonfile.close() # close the json file | |
## working with buffered content | |
data['host'] = given_ip | |
## save our changes to json file | |
jsonfile = open(filename, "w+") | |
jsonfile.write(json.dumps(data)) | |
jsonfile.close() | |
a = subprocess.check_output(['aws', | |
'ec2', | |
'describe-instances', | |
'--instance-ids', | |
'i-095dbe3e1a672ed60']) | |
obj = json.loads(a) | |
ip = (obj['Reservations'] | |
[0]['Instances'] | |
[0]['NetworkInterfaces'] | |
[0]['Association'] | |
['PublicIp']) | |
update_json_file(ip, FNAME) | |
print "ssh ubuntu@{0}".format(ip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment