diff --git a/tsshbatch.py b/tsshbatch.py index 0fb0184..3b076bf 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -15,7 +15,7 @@ PROGNAME = "tsshbatch.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tsshbatch.py,v 1.128 2011/12/30 23:50:22 tundra Exp $" +RCSID = "$Id: tsshbatch.py,v 1.129 2012/01/04 19:22:35 tundra Exp $" VERSION = RCSID.split()[2] CPRT = "(c)" @@ -62,7 +62,8 @@ SEPARATOR = " ---> " SUCCESS = "SUCCESS" SUDO = 'sudo' -SUDOARGS = '-S' +SUDOPROMPT = 'READINGSUDOPW' +SUDOARGS = '-S -p %s' % SUDOPROMPT TRAILER = ": " USAGE = \ PROGVER + "\n" +\ @@ -84,6 +85,7 @@ eBADARG = "Invalid command line: %s!" eBADFILE = "Cannot open '%s'!" +eBADSUDO = "sudo Failed, Check Password Or Command! sudo Error Report: %s" eFEWARGS = "Too few command line arguments!" eNOCONNECT = "Cannot Connect! (Name/Address Bad? Destination Unreachable?)" eNOLOGIN = "Cannot Login! (Login/Password Bad?)" @@ -163,7 +165,19 @@ if command.startswith(SUDO): stdin.write("%s\n" % pw) stdin.flush() - + + # If all we see on stderr at this point is our original + # prompt, then then the sudo promotion worked. A bad + # 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)[1].strip() + if sudonoise: + PrintReport([host, FAILURE, eBADSUDO % sudonoise], HANDLER=PrintStderr) + ssh.close() + return + PrintReport([host + " (stdout)", SUCCESS] + stdout.readlines()) if REPORTERR: