diff --git a/tsshbatch.py b/tsshbatch.py index 1a7fe38..bdf93fc 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.168 2013/10/29 14:12:24 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.169 2013/10/29 14:35:03 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" DATE = "2011-2013" @@ -456,11 +456,9 @@ fname = ConditionLine(line.split(INCLUDE)[1]) ReadFile(fname, envvar, listcontainer, containingfile=filename) + # It's an ordinary line - do variable substitution and save else: - - for symbol in SymbolTable: - line = line.replace(symbol, SymbolTable[symbol]) - listcontainer.append(line) + listcontainer.append(VarSub(line)) f.close() FileIncludeStack.pop() # Remove this invocation from the stack @@ -506,6 +504,19 @@ # End of 'SearchPath()' +##### +# Do Variable Substitution In A String +##### + +def VarSub(line): + + for symbol in SymbolTable: + line = line.replace(symbol, SymbolTable[symbol]) + + return line + +# End of 'VarSub()' + # ---------------------- Program Entry Point ---------------------- # ##### @@ -604,10 +615,15 @@ # are understood to form the command. else: + # First, do variable substitution on passed hosts + for index in range(len(Hosts)): + Hosts[index] = VarSub(Hosts[index]) + + # Now save the command command = " ".join(args[0:]) -# Put it in a list data structure because this is what the +# Put command in a list data structure because this is what the # HostCommands() function expects. This is necessary to handle multi # command input from from a file. @@ -616,11 +632,7 @@ if command: # Do variable substitution here like any other command - - for symbol in SymbolTable: - command = command.replace(symbol, SymbolTable[symbol]) - - Commands.append(command) + Commands.append(VarSub(command)) ##### # Authentication Credential Processing @@ -648,12 +660,12 @@ current_user = UNAME UNAME = raw_input(pUSER %current_user) if not UNAME: # User just hit return - wants default - UNAME = current_user + Uname = Current_User - # Preset commandline and/or program option variable password takes precedence + # Preset Commandline And/Or Program Option Variable Password Takes Precedence - if not PWORD: - PWORD = getpass.getpass(pPASS) + If Not Pword: + Pword = Getpass.getpass(pPASS) ##### # If Needed, Get sudo Password