|
|
|
@ -1,8 +1,11 @@ |
|
|
|
#!/usr/bin/python |
|
|
|
import subprocess |
|
|
|
import argparse |
|
|
|
import configparser |
|
|
|
import os |
|
|
|
HOME = os.path.expandvars('$HOME') |
|
|
|
cp = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation()) |
|
|
|
cp.read('hostnames.ini') |
|
|
|
cp.read('{HOME}/.ssh/config/hostnames.ini'.format(HOME=HOME)) |
|
|
|
if __name__ == "__main__": |
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
group = parser.add_mutually_exclusive_group(required=True) |
|
|
|
@ -13,12 +16,12 @@ if __name__ == "__main__": |
|
|
|
parser.add_argument('arg',nargs = '*') |
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
if pre: |
|
|
|
pre = '~/.ssh/config/{}'.format(args.pre_script) |
|
|
|
if args.pre_script: |
|
|
|
pre = '{HOME}/.ssh/config/{}'.format(args.pre_script,HOME=HOME) |
|
|
|
subprocess.check_call(pre) |
|
|
|
if args.wan: |
|
|
|
host = cp['wan'][args.name] |
|
|
|
elif args.lan: |
|
|
|
host = cp['lan'][args.name] |
|
|
|
cmd = ['ssh','-F','~/.ssh/{}.cfg'.format(args.name),host] + args.arg |
|
|
|
cmd = ['ssh','-F','{HOME}/.ssh/config/{}.cfg'.format(args.name,HOME=HOME),host] + args.arg |
|
|
|
subprocess.call(cmd) |