diff --git a/tsshbatch.py b/tsshbatch.py index bf721f6..5e87dc7 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -9,7 +9,7 @@ PROGNAME = "tsshbatch.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tsshbatch.py,v 1.116 2011/11/04 19:32:56 tundra Exp $" +RCSID = "$Id: tsshbatch.py,v 1.117 2011/11/04 20:08:28 tundra Exp $" VERSION = RCSID.split()[2] @@ -45,6 +45,7 @@ PADWIDTH = 30 SEPARATOR = " ---> " SUCCESS = "SUCCESS" +SUDO = 'sudo' TRAILER = ": " USAGE = "Usage: tsshbatch.py [-k] [-n name] [-p pw] [-h 'host host ..' | serverlistfile] command arg arg arg \n" +\ " where,\n" +\ @@ -61,7 +62,7 @@ eBADFILE = "Cannot open '%s'!" eNOCONNECT = "Cannot Connect! (Name/Address Bad? Destination Unreachable?)" eNOLOGIN = "Cannot Login! (Login/Password Bad?)" - +eSUDOPW = "Must Specify Password When Using %s Commands!" % SUDO ##### # Prompts @@ -111,7 +112,17 @@ else: ssh.connect(host, username=user, password=pw) +# chan = ssh.invoke_shell() +# stdin, stdout, stderr = chan.exec_command('tty') +# stdin.write("%s\n" % command) stdin, stdout, stderr = ssh.exec_command(command) + + # Handle sudo commands + + if command.startswith(SUDO): + stdin.write("%s\n" % pw) + stdin.flush() + PrintReport([host, SUCCESS] + stdout.readlines() + stderr.readlines()) # Catch authentication problems explicitly @@ -241,6 +252,13 @@ else: CMD = " ".join(args[0:]) +# If user want 'sudo' execution, they MUST provide a password +# because key exchange-based authentication is not part of sudo + +CMD = CMD.strip() +if CMD.startswith(SUDO) and not PWORD: + ErrorExit(eSUDOPW) + # Iterate over the list of hosts, executing the command for host in HOSTS: