diff --git a/tsshbatch.py b/tsshbatch.py index 8fc8ef8..1b75dae 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,8 +20,8 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.228 2016/01/18 23:23:18 tundra Exp $" -VERSION = CVSID.split()[2] +GITID = "$Id: tsshbatch.py,v 1.228 2016/01/18 23:23:18 tundra Exp $" +VERSION = GITID.split()[2] CPRT = "(c)" PROGDATE = "2011-2016" OWNER = "TundraWare Inc." @@ -33,7 +33,7 @@ ##### -# Suppress Deprecation Warnings +# Suppress Deprecation Warnings # Required in some older environments where paramiko version # is behind the python libs version. ##### @@ -270,7 +270,7 @@ if InLiteral: if char == quote_char: InLiteral = False - + elif char in quote_chars: quote_char = char InLiteral = True @@ -279,7 +279,7 @@ search += char index += 1 - + status = False if search.count(key) > 0: status = True @@ -334,7 +334,7 @@ PrintStdout(BANNERMSG % (BANNERSTART, time.strftime("%Y-%m-%d"), time.strftime("%H:%M:%S"))) PrintStdout(BANNERTIME % float(time.time() - StartTime)) - + os._exit(1) @@ -359,7 +359,7 @@ srcfile = VarSub(src) for destdir in filelist[src]: - + # Process any .define substitutions destdir = VarSub(destdir) @@ -419,7 +419,7 @@ # End of 'HostFileTransfer()' - + def HostCommands(host, user, pw, sudopw, commands): # Figure out if we want report formatting @@ -429,7 +429,7 @@ Format = False # Connect and run the command, reporting results as we go - try: + try: ssh = SSH_Connect(host, user, pw, TIMEOUT) if NOISELEVEL != QUIET: PrintReport([host, CONSUCCESS], FORMAT=Format) @@ -453,7 +453,7 @@ if KeyInString(SUDO + " ", command): command = command.replace(SUDO, "%s %s" % (SUDO, SUDOARGS), 1) - + stdin, stdout, stderr = ssh.exec_command(command) # If doing a sudo command, send the password @@ -461,7 +461,7 @@ if KeyInString(SUDO + " ", command): stdin.write("%s\n" % sudopw) 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 @@ -482,7 +482,7 @@ raise SystemExit else: break - + cmdreport = " [%s]" % command if NOISELEVEL == QUIET: cmdreport = "" @@ -493,15 +493,15 @@ PrintReport([host + " (stderr)" + cmdreport, "\n"] + stderr.readlines() + ["\n"], HANDLER=PrintStderr, FORMAT=Format) # Handle aborts - + except SystemExit: ErrorExit(ABORTING) # Catch authentication problems explicitly - + except paramiko.AuthenticationException: PrintReport([host, eCMDFAILURE % eNOLOGIN], HANDLER=PrintStderr) - + # Everything else is some kind of connection problem except: @@ -603,11 +603,11 @@ f = open(filename) for line in f.readlines(): - + # Cleanup comments and whitespace line = ConditionLine(line) - + # Process file transfer requests if line.startswith(FILEGET): @@ -621,7 +621,7 @@ # Process variable definitions elif line.startswith(DEFINE): - + line = line.split(DEFINE)[1] if line.count(ASSIGN) == 0: ErrorExit(eBADDEFINE % line) @@ -718,7 +718,7 @@ except: PrintStderr(iNOCFGFILE % filename) return retval - + sshconfig.parse(f) f.close() @@ -755,7 +755,7 @@ # Handle fully qualified filenames # But ignore this, if its a directory with a matching name - + if os.path.exists(filename) and os.path.isfile(filename): retval = os.path.realpath(filename) @@ -786,7 +786,7 @@ for symbol in SymbolTable: line = line.replace(symbol, SymbolTable[symbol]) - + return line # End of 'VarSub()' @@ -842,11 +842,11 @@ if opt == "-H": Hosts = val.split() - + if opt == "-N": PROMPTUSERNAME = True KEYEXCHANGE = False - + if opt == "-P": ProcessTXRQ(val, Put_Transfer_List) @@ -861,20 +861,20 @@ if opt == "-a": ABORTONFXERROR = False - + if opt == "-b": ABORTBADSUDO = False - + if opt == "-e": REPORTERR = False - - if opt == "-f": + + if opt == "-f": Commands = ReadFile(val, os.getenv(CMDINCL), Commands) - + if opt == "-h": PrintStdout(USAGE) sys.exit() - + if opt == "-k": KEYEXCHANGE = True @@ -897,7 +897,7 @@ TESTMODE = True if opt == "-v": - PrintStdout(CVSID) + PrintStdout(GITID) sys.exit() if opt == "-x": @@ -934,10 +934,10 @@ Hosts = ReadFile(args[0], os.getenv(HOSTINCL), Hosts) command = " ".join(args[1:]) - + # If hosts were passed on the command line, all the arguments # are understood to form the command. - + else: command = " ".join(args[0:]) @@ -970,7 +970,7 @@ if not UNAME: UNAME = os.getenv(USERVAR) - + # By default, use the above as the login name and don't prompt for it # unless overriden on the command line with -N @@ -1000,7 +1000,7 @@ # The user is prompted for a sudo password under two conditions: # # 1) -k option was selected but no password was set with -p -# 2) -S option was selected +# 2) -S option was selected # # If the user IS prompted for a sudo password, any login password # previously entered - either via -p or interactive entry - will be @@ -1032,7 +1032,7 @@ if PWORD and not SUDOPW: SUDOPW = PWORD - + # Report time statistics if requested if BANNERSON: @@ -1065,7 +1065,7 @@ for dest in xfers[source]: # Dereference any variables in the file transfer specification - + source = VarSub(source) dest = VarSub(dest) @@ -1102,10 +1102,10 @@ # executing any file transfers and commands. Accomodate commenting # out hosts in a list. -else : +else : # Pick up any local configuration data - + SSH_Configuration = SSH_GetConfig(SSHCFGFILE) # Check to see if user is trying to override any builtins @@ -1168,7 +1168,6 @@ ##### if BANNERSON: - + PrintStdout(BANNERMSG % (BANNEREND, time.strftime("%Y-%m-%d"), time.strftime("%H:%M:%S"))) PrintStdout(BANNERTIME % float(time.time() - StartTime)) -