Skip to content

Instantly share code, notes, and snippets.

@chriskvik
Last active August 13, 2017 16:17
Show Gist options
  • Save chriskvik/c906c96dfd9cc266cd337ac158a9ab61 to your computer and use it in GitHub Desktop.
Save chriskvik/c906c96dfd9cc266cd337ac158a9ab61 to your computer and use it in GitHub Desktop.
import os
import getpass
def make_executable(path):
mode = os.stat(path).st_mode
mode |= (mode & 0o444) >> 2
os.chmod(path, mode)
entry = []
try:
with open('/home/{0}/.ssh/config'.format(getpass.getuser())) as f:
for line in f:
if 'Host' in line.split():
entry.append(line.rstrip().split(' ')[1])
except IOError:
print('Check if ssh config exists..')
print(entry)
try:
for ent in entry:
path = '/home/{0}/bin/{1}'.format(getpass.getuser(),ent)
try:
f = open(path, 'r')
except IOError:
with open(path, 'w') as f:
f.write('#!/bin/sh\n')
f.write('gnome-terminal -e "ssh {0}"'.format(ent))
make_executable(path)
except IOError:
print('Is {0} a valid path?'.format(path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment