diff --git a/TODO b/TODO index 455689b..5fe3478 100644 --- a/TODO +++ b/TODO @@ -21,8 +21,11 @@ - Option to read from stdin -- -H and hostlist files are now additive +- Cosmetic changes in reporting output +- Cleaned up sudo handling and reporting + +- Note ability to have a different login and sudo pw via -k + sudo ... diff --git a/tsshbatch.py b/tsshbatch.py index 28d495f..f47b5eb 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -17,7 +17,7 @@ PROGNAME = "tsshbatch.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -CVSID = "$Id: tsshbatch.py,v 1.146 2013/10/22 22:59:17 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.147 2013/10/23 02:25:24 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" @@ -95,7 +95,7 @@ eBADARG = "Invalid command line: %s!" eBADFILE = "Cannot open '%s'!" -eBADSUDO = "sudo Failed, Check Password Or Command! sudo Error Report: %s" +eBADSUDO = "sudo Failed (Check Password Or Command!) sudo Error Report: %s" eBADTXRQ = "Bad Transfer Request: %s Must Have Exactly 1 Source And 1 Destination!" eFXERROR = "File Transfer Error: %s" eNOCONNECT = "Cannot Connect To %s" @@ -223,17 +223,22 @@ for command in commands: + # It's possible to get blank lines from stdin. + # Ignore them. + + if not command: + continue + # If this is a sudo run, force password to be read # from stdin thereby avoiding fiddling around with ptys. if command.startswith(SUDO + " "): command = command.replace(SUDO, "%s %s" % (SUDO, SUDOARGS), 1) - - + stdin, stdout, stderr = ssh.exec_command(command) - + # If doing a sudo command, send the password - + if command.startswith(SUDO + " "): stdin.write("%s\n" % pw) stdin.flush() @@ -243,17 +248,11 @@ # password or bad command will generate additional noise # from sudo telling us to try again or that there was a # command error. - - sudonoise = stderr.readline().split(SUDOPROMPT) - - if len(sudonoise) > 1: # sudo had problems - sudonoise = sudonoise[1].strip() - - else: # sudo OK - sudonoise = "" - - if sudonoise: - PrintReport([host + " [%s]" % command, FAILURE % (eBADSUDO % sudonoise)], HANDLER=PrintStderr) + + sudonoise = " ".join(stderr.readline().split(SUDOPROMPT)).strip() + + if sudonoise: # sudo had problems + PrintReport([host + " [%s]" % command, FAILURE % (eBADSUDO % sudonoise)] + ["\n"], HANDLER=PrintStderr) ssh.close() return