diff --git a/tsshbatch.py b/tsshbatch.py index 5e87dc7..352eed0 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.117 2011/11/04 20:08:28 tundra Exp $" +RCSID = "$Id: tsshbatch.py,v 1.118 2011/11/15 20:56:27 tundra Exp $" VERSION = RCSID.split()[2] @@ -46,6 +46,7 @@ SEPARATOR = " ---> " SUCCESS = "SUCCESS" SUDO = 'sudo' +SUDOARGS = '-S' TRAILER = ": " USAGE = "Usage: tsshbatch.py [-k] [-n name] [-p pw] [-h 'host host ..' | serverlistfile] command arg arg arg \n" +\ " where,\n" +\ @@ -112,12 +113,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) + # 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)) + + # Run the command + stdin, stdout, stderr = ssh.exec_command(command) - # Handle sudo commands + # If doing a sudo command, send the password if command.startswith(SUDO): stdin.write("%s\n" % pw)