diff --git a/tsshbatch.py b/tsshbatch.py index 1bc5e3c..21022c5 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -12,9 +12,18 @@ PROGNAME = "tsshbatch.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tsshbatch.py,v 1.119 2011/12/28 17:54:42 tundra Exp $" +RCSID = "$Id: tsshbatch.py,v 1.120 2011/12/28 18:35:04 tundra Exp $" VERSION = RCSID.split()[2] +CPRT = "(c)" +DATE = "2011" +OWNER = "TundraWare Inc." +RIGHTS = "All Rights Reserved." +COPYRIGHT = "Copyright %s %s, %s %s" % (CPRT, DATE, OWNER, RIGHTS) + +PROGVER = PROGNAME + " " + VERSION + (" - %s" % COPYRIGHT) +HOMEPAGE = "http://www.tundraware.com/Software/%s\n" % BASENAME + ##### # Suppress Deprecation Warnings @@ -44,26 +53,33 @@ FAILURE = "FAILURE" INDENTWIDTH = 8 -OPTIONSLIST = "h:kn:p:" +OPTIONSLIST = "H:hkn:p:v" PADWIDTH = 30 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" +\ +USAGE = \ + PROGVER + "\n" +\ + HOMEPAGE + "\n\n" +\ + "Usage: tsshbatch.py [-h] [-v] [-k] [-n name] [-p pw] [-H 'host host ..' | serverlistfile] command arg arg arg \n" +\ " where,\n" +\ "\n" +\ - " -h '...' List of targeted hosts passed as a single argument\n" +\ - " -k Turns on key-exchange authentication\n" +\ - " -n name Specifies login name\n" +\ - " -p pw Specifies login password\n" + " -H '...' List of targeted hosts passed as a single argument\n" +\ + " -h Display help\n" +\ + " -k Turn on key-exchange authentication\n" +\ + " -n name Specify login name\n" +\ + " -p pw Specify login password\n" +\ + " -v Display extended program version information\n" + ##### # Error Messages ##### eBADARG = "Invalid command line: %s!" eBADFILE = "Cannot open '%s'!" +eFEWARGS = "Too few command line arguments!" eNOCONNECT = "Cannot Connect! (Name/Address Bad? Destination Unreachable?)" eNOLOGIN = "Cannot Login! (Login/Password Bad?)" eSUDOPW = "Must Specify Password When Using %s Commands!" % SUDO @@ -93,7 +109,7 @@ def ErrorExit(msg): PrintStdout(msg) - sys.exit() + sys.exit(1) # End Of 'ErrorExit()' @@ -197,16 +213,22 @@ except getopt.GetoptError, (errmsg, badarg): ErrorExit(eBADARG % errmsg) -# Make sure we have sufficient command line args -# to do something useful - -if len(args) < 2: - ErrorExit(USAGE) +# Unless the -H option is selected, this program +# requires a minimum of 2 command line arguments +# to run (hostlist file and command). If the user +# specifies -H, then all we need is the command. + +MINARGS = 2 for opt, val in opts: - if opt == "-h": + if opt == "-H": HOSTS = val.split() + MINARGS = 1 + + if opt == "-h": + PrintStdout(USAGE) + sys.exit() if opt == "-k": KEYEXCHANGE = True @@ -216,7 +238,17 @@ if opt == "-p": PWORD = val - + + if opt == "-v": + PrintStdout(RCSID) + sys.exit() + +# Make sure we have enough args to do the job + +if len(args) < MINARGS: + ErrorExit(eFEWARGS) + + ##### # Go Do The Requested Work #####