diff --git a/tsshbatch.py b/tsshbatch.py index 5283066..9573e6b 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.223 2016/01/17 02:03:28 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.224 2016/01/18 20:56:47 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" PROGDATE = "2011-2016" @@ -70,6 +70,10 @@ BANNERSTART = 'Started' COMMENT = '#' COMMANDS = 'Commands' +CFGENTRY = 'config' +CFGHOST = 'host' +CFGID = 'identityfile' +CFGREALHOST = 'hostname' CONSUCCESS = 'SUCCESS: Connection Established' EXECUTE = '!' FILEGET = '.getfile' @@ -157,13 +161,6 @@ ##### -# Global Symbol Table -##### - -SymbolTable = {} - - -##### # Error Messages ##### @@ -213,7 +210,7 @@ PWORD = "" # Password REDIRSTDERR = False # Redirect stderr to stdout REPORTERR = True # Report stderr output from remote host -SSHCONFIGFILE = "~/.ssh/config" # Default ssh configuration file location +SSHCFGFILE = "~/.ssh/config" # Default ssh configuration file location TESTMODE = True # Run program in test mode, don't actually execute commands TIMEOUT = 15 # Connection attempt timeout (sec) UNAME = "" # Login name @@ -228,7 +225,7 @@ ##### -# Global Data Structures +# Global Data Structures & Variables ##### Commands = [] @@ -236,6 +233,7 @@ Get_Transfer_List = collections.OrderedDict() Put_Transfer_List = collections.OrderedDict() SSH_Configuration = {} +SymbolTable = {} ##### @@ -335,7 +333,7 @@ if BANNERSON: PrintStdout(BANNERMSG % (BANNERSTART, time.strftime("%Y-%m-%d"), time.strftime("%H:%M:%S"))) - PrintStdout(BANNERTIME % cloat(time.time() - starttime)) + PrintStdout(BANNERTIME % float(time.time() - StartTime)) os._exit(1) @@ -705,17 +703,20 @@ with open(os.path.expanduser(filename)) as f: - cfg = paramiko.SSHConfig() - cfg.parse(f) - ret_dict = {} + sshconfig = paramiko.SSHConfig() + sshconfig.parse(f) + configuration = {} - for d in cfg._config: - _copy = dict(d) - del _copy['host'] - for host in d['host']: - ret_dict[host] = _copy['config'] + 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 ret_dict + return configuration # End of 'SSH_GetConfig()' @@ -772,6 +773,14 @@ # ---------------------- Program Entry Point ---------------------- # ##### +# Note starting time +##### + +StartTime = time.time() # Need this here in case we error abort + # on command line processing. Gets + # reset below for normal processing. + +##### # Process Any Options User Set In The Environment Or On Command Line ##### @@ -999,17 +1008,16 @@ SUDOPW = PWORD -##### -# Do The Requested Work -##### - # Report time statistics if requested if BANNERSON: - - starttime = time.time() + StartTime= time.time() # The the real starting time - the time the work began PrintStdout(BANNERMSG % (BANNERSTART, time.strftime("%Y-%m-%d"), time.strftime("%H:%M:%S"))) +##### +# Do The Requested Work +##### + # If we're running testmode, just report the final list of # hosts and commands that would be run @@ -1073,7 +1081,7 @@ # Get the local SSH configuration - SSH_Config = SSH_GetConfig(SSHCONFIGFILE) + SSH_Config = SSH_GetConfig(SSHCFGFILE) # Check to see if user is trying to override any builtins @@ -1137,5 +1145,5 @@ if BANNERSON: PrintStdout(BANNERMSG % (BANNEREND, time.strftime("%Y-%m-%d"), time.strftime("%H:%M:%S"))) - PrintStdout(BANNERTIME % float(time.time() - starttime)) + PrintStdout(BANNERTIME % float(time.time() - StartTime))