diff --git a/TODO b/TODO index 7aa41da..6f432bc 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,7 @@ -- Fix error reporting blowout when key-exchange auth fails +- Added -E to redirect all stderr output to stdout instead - Added -T timeout option (default is 15 sec) - Added -a to allow program to continue after file transfer error +- Fix error reporting blowout when key-exchange auth fails - Error messages now more consistent and clear @@ -10,7 +11,6 @@ - Fix password prompting with -K + sudo - Fix "no handlers" error - Check command line for 'sudo' invocations -- Switch to force errors to be written to stdout diff --git a/tsshbatch.py b/tsshbatch.py index 8215c8f..2522165 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.183 2014/03/28 21:12:26 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.184 2014/07/25 15:43:35 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" DATE = "2011-2014" @@ -69,7 +69,7 @@ HOSTNOISE = '[%s]' HOSTLIST = 'Hosts' INDENTWIDTH = 8 -OPTIONSLIST = 'KG:H:NP:ST:aef:hkn:p:tvxy' +OPTIONSLIST = 'EKG:H:NP:ST:aef:hkn:p:tvxy' PADWIDTH = 12 PATHDELIM = ':' PATHSEP = os.sep @@ -88,9 +88,10 @@ USAGE = \ PROGVER + "\n" +\ HOMEPAGE + "\n\n" +\ - "Usage: tsshbatch.py [-NSTaehkvxy -G 'file dest' -P 'file dest' -f cmdfile -n name -p pw ] -H 'host ..' | hostlistfile [command arg ... ]\n" +\ + "Usage: tsshbatch.py [-EKNSTaehkvxy -G 'file dest' -P 'file dest' -f cmdfile -n name -p pw ] -H 'host ..' | hostlistfile [command arg ... ]\n" +\ " where,\n" +\ "\n" +\ + " -E Write error output to stdout instead of stderr\n" +\ " -K Force password prompting - Overrides previous -k\n" +\ " -G 'file dest' GET file on host and write local dest directory\n" +\ " -H '...' List of targeted hosts passed as a single argument\n" +\ @@ -178,6 +179,7 @@ NOISY = False # Print output with extra detail PROMPTUSERNAME = False # Don't use $USER, prompt for username PWORD = "" # Password +REDIRSTDERR = False # Redirect stderr to stdout REPORTERR = True # Report stderr output from remote host TESTMODE = True # Run program in test mode, don't actually execute commands TIMEOUT = 15 # Connection attempt timeout (sec) @@ -211,8 +213,16 @@ ##### def PrintStderr(msg, TERMINATOR="\n"): - sys.stderr.write(msg + TERMINATOR) - sys.stderr.flush() + + # If we've been told to redirect to stdout, do so instead + + if REDIRSTDERR: + PrintStdout(msg, TERMINATOR) + + else: + + sys.stderr.write(msg + TERMINATOR) + sys.stderr.flush() # End of 'PrintStderr()' @@ -587,6 +597,10 @@ for opt, val in opts: + + if opt == "-E": + REDIRSTDERR = True + if opt == "-K": KEYEXCHANGE = False diff --git a/tsshbatch.rst b/tsshbatch.rst index ca59a56..7bbea08 100644 --- a/tsshbatch.rst +++ b/tsshbatch.rst @@ -9,7 +9,7 @@ -------- :: - tsshbatch.py [-KNSaehktvxy -G 'file dest' -P 'file dest' -f cmdfile -n name -p pw ] -H 'host ..' | hostlistfile [command arg ... ] + tsshbatch.py [-EKNSaehktvxy -G 'file dest' -P 'file dest' -f cmdfile -n name -p pw ] -H 'host ..' | hostlistfile [command arg ... ] DESCRIPTION @@ -39,6 +39,18 @@ on either the command line or in the ``$TSSHBATCH`` environment variable: + -E Normally, ``tsshbatch`` writes it's own errors + to ``stderr``. It also writes the ``stderr`` + output from each host it contacts to the local + shell's ``stderr`` (unless the ``-e`` option has + been selected). + + The ``-E`` option redirects any such ``tsshbatch`` + output intended for ``stderr`` to ``stdout`` + instead. This avoids the need to do things like + ``2>&1 | ...` on the command line when you want to + pipe all ``tsshbatch`` output to another program. + -K Force prompting for passwords. This is used to override a prior ``-k`` argument. @@ -86,7 +98,7 @@ -a Don't abort program after failed file transfers. Continue to next transfer attempt. (Default: Abort) - -e Don't report remote host stderr output + -e Don't report remote host ``stderr`` output -f cmdfile Read commands from a file. This file can be commented freely with the ``#`` character. Leading- and @@ -762,7 +774,7 @@ :: - $Id: tsshbatch.rst,v 1.138 2014/03/28 21:05:13 tundra Exp $ + $Id: tsshbatch.rst,v 1.139 2014/07/25 15:43:35 tundra Exp $ You can find the latest version of this program at: