From 997d808fc175eccb11938291de470d14d7ae2b5e Mon Sep 17 00:00:00 2001 From: rlbr Date: Wed, 24 Oct 2018 00:58:54 -0500 Subject: [PATCH] --ssh-opt: mechanism for passing arg to ssh --- ssh-host.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ssh-host.py b/ssh-host.py index 3171654..9449d39 100755 --- a/ssh-host.py +++ b/ssh-host.py @@ -3,6 +3,7 @@ import subprocess import argparse import configparser import os +import shlex HOME = os.path.expandvars('$HOME') cp = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation()) cp.read('{HOME}/.ssh/config/hostnames.ini'.format(HOME=HOME)) @@ -11,11 +12,11 @@ if __name__ == "__main__": 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('-p','--pre-script', help= 'script to run before connecting(script must be in config dir)') + parser.add_argument('--ssh-opt',help='pass options to ssh command, use "+" instead of "-"') parser.add_argument('name',help='name of config file to use (sans .cfg)') - parser.add_argument('arg',nargs = '*') + parser.add_argument('cmd',nargs = '*',help = 'command to be run') args = parser.parse_args() - if args.pre_script: pre = '{HOME}/.ssh/config/{}'.format(args.pre_script,HOME=HOME) subprocess.check_call(pre) @@ -23,5 +24,8 @@ if __name__ == "__main__": 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) + cmd = ['ssh','-F','{HOME}/.ssh/config/{}.cfg'.format(args.name,HOME=HOME)] + if args.ssh_opt: + cmd += shlex.split(args.ssh_opt.replace('+','-')) + cmd += [host] + args.arg + subprocess.call(cmd) \ No newline at end of file