diff --git a/tsshbatch.py b/tsshbatch.py index 9573e6b..a467995 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.224 2016/01/18 20:56:47 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.225 2016/01/18 22:05:17 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" PROGDATE = "2011-2016" @@ -70,9 +70,7 @@ BANNERSTART = 'Started' COMMENT = '#' COMMANDS = 'Commands' -CFGENTRY = 'config' -CFGHOST = 'host' -CFGID = 'identityfile' +CFGKEYID = 'identityfile' CFGREALHOST = 'hostname' CONSUCCESS = 'SUCCESS: Connection Established' EXECUTE = '!' @@ -183,7 +181,8 @@ # Informational Messages ##### -iTXFILE = "Writing %s To %s ..." +iNOCFGFILE = "Warning: Cannot Open File '%s'! Continuing Anyway ..." +iTXFILE = "Writing %s To %s ..." ##### @@ -701,23 +700,27 @@ def SSH_GetConfig(filename): - with open(os.path.expanduser(filename)) as f: + retval = {} + sshconfig = paramiko.SSHConfig() + try: + f = open(os.path.expanduser(filename)) - sshconfig = paramiko.SSHConfig() - sshconfig.parse(f) - configuration = {} + # File open failed, but we go on anyway + except: + PrintStderr(iNOCFGFILE % filename) + return sshconfig + + sshconfig.parse(f) + f.close() - for entry in sshconfig._config: - - for hostname in entry[CFGHOST]: - print hostname -# print entry[CFGENTRY].keys() -# print entry[CFGENTRY][CFGID] -# print entry[CFGENTRY][CFGREALHOST] - + # Return local configuration as a dictonary with hostnames as keys - return configuration + for host in sshconfig.get_hostnames(): + if host != "*": + cfgentry = sshconfig.lookup(host) + retval[host] = [cfgentry[CFGKEYID], cfgentry[CFGREALHOST]] + return retval # End of 'SSH_GetConfig()' @@ -1079,10 +1082,10 @@ else : - # Get the local SSH configuration - - SSH_Config = SSH_GetConfig(SSHCFGFILE) + # Pick up any local configuration data + SSH_Configuration = SSH_GetConfig(SSHCFGFILE) + # Check to see if user is trying to override any builtins protected = []