diff --git a/tsshbatch.py b/tsshbatch.py index 12e9cb2..13d129d 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.205 2014/12/08 15:50:42 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.206 2014/12/08 18:19:11 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" PROGDATE = "2011-2014" @@ -394,6 +394,12 @@ def HostCommands(host, user, pw, sudopw, commands): + # Figure out if we want report formatting + + Format = True + if NOISELEVEL == SILENT: + Format = False + ssh = paramiko.SSHClient() # Connect and run the command, reporting results as we go @@ -408,7 +414,7 @@ ssh.connect(host, username=user, password=pw, allow_agent=False, look_for_keys=False, timeout=TIMEOUT) if NOISELEVEL != QUIET: - PrintReport([host, CONSUCCESS]) + PrintReport([host, CONSUCCESS], FORMAT=Format) # Run all requested commands @@ -455,10 +461,10 @@ if NOISELEVEL == QUIET: cmdreport = "" - PrintReport([host + " (stdout)" + cmdreport, "\n"] + stdout.readlines() + ["\n"]) + PrintReport([host + " (stdout)" + cmdreport, "\n"] + stdout.readlines() + ["\n"], FORMAT=Format) if REPORTERR: - PrintReport([host + " (stderr)" + cmdreport, "\n"] + stderr.readlines() + ["\n"], HANDLER=PrintStderr) + PrintReport([host + " (stderr)" + cmdreport, "\n"] + stderr.readlines() + ["\n"], HANDLER=PrintStderr, FORMAT=Format) # Handle aborts @@ -488,10 +494,10 @@ # Uses print handler to stdout by default but can be overriden at call # time to invoke any arbitrary handler function. -def PrintReport(results, HANDLER=PrintStdout): +def PrintReport(results, HANDLER=PrintStdout, FORMAT=True): - if NOISELEVEL != SILENT: + if FORMAT: hostname = results[0] HANDLER(SEPARATOR + hostname + @@ -508,10 +514,10 @@ for r in results[2:]: # Command Results HANDLER(hostnoise + INDENTWIDTH * " " + r.strip()) - # In silent mode we just return results with no headers or formatting. - # We suppress the last line in the list. It is an empty line - # introduced for formatting by the caller, but isn't really part - # of the returned output. + # In (silent) unformatted mode we just return results with no + # headers or formatting. We suppress the last line in the list. + # It is an empty line introduced for formatting by the caller, but + # isn't really part of the returned output. else: for r in results[2:-1]: