You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.1 KiB
27 lines
1.1 KiB
#!/usr/bin/python
|
|
import subprocess
|
|
import argparse
|
|
import configparser
|
|
import os
|
|
HOME = os.path.expandvars('$HOME')
|
|
cp = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
|
|
cp.read('{HOME}/.ssh/config/hostnames.ini'.format(HOME=HOME))
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
group = parser.add_mutually_exclusive_group(required=True)
|
|
group.add_argument('-o','--wan',action = 'store_true')
|
|
group.add_argument('-l','--lan',action = 'store_true')
|
|
parser.add_argument('-p','--pre-script', help= 'script to run before connecting(in config dir)')
|
|
parser.add_argument('name',help='name of config file to use (sans .cfg)')
|
|
parser.add_argument('arg',nargs = '*')
|
|
args = parser.parse_args()
|
|
|
|
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','{HOME}/.ssh/config/{}.cfg'.format(args.name,HOME=HOME),host] + args.arg
|
|
subprocess.call(cmd)
|