diff --git a/tsshbatch.py b/tsshbatch.py index c193920..a01c688 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -17,7 +17,7 @@ PROGNAME = "tsshbatch.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -CVSID = "$Id: tsshbatch.py,v 1.155 2013/10/23 19:17:37 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.156 2013/10/23 22:22:26 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" @@ -340,6 +340,26 @@ # End of 'ProcessTXRQ' +##### +# Read File Handling Comments And Metacommands +##### + +def ReadFile(filename, listcontainer): + try: + f = open(filename) + for line in f.readlines(): + line = ConditionLine(line) + if line: + listcontainer.append(line) + f.close() + + return listcontainer + + except: + ErrorExit(eBADFILE % filename) + +# End of 'ReadFile()' + # ---------------------- Program Entry Point ---------------------- # @@ -350,7 +370,7 @@ # Options that can be overriden by user GETSUDOPW = False # Prompt for sudo password -HOSTS = "" # List of hosts to target +HOSTS = [] # List of hosts to target KEYEXCHANGE = False # Do key exchange-based auth? PROMPTUSERNAME = False # Don't use $USER, prompt for username PWORD = "" # Password @@ -401,15 +421,7 @@ REPORTERR = False if opt == "-f": - try: - f = open(val) - for line in f.readlines(): - line = ConditionLine(line) - if line: - Commands.append(line) - f.close() - except: - ErrorExit(eBADFILE % val) + Commands = ReadFile(val, Commands) if opt == "-h": PrintStdout(USAGE) @@ -446,14 +458,7 @@ if not args: ErrorExit(eNOHOSTS) - try: - f = open(args[0]) - HOSTS = f.readlines() - f.close() - - except: - ErrorExit(eBADFILE % args[0]) - + HOSTS = ReadFile(args[0], HOSTS) command = " ".join(args[1:]) # If hosts were passed on the command line, all the arguments @@ -558,14 +563,11 @@ for host in HOSTS: - host = ConditionLine(host) - if host: - - if Get_Transfer_List: - HostFileTransfer(host, UNAME, PWORD, Get_Transfer_List, GET=True) + if Get_Transfer_List: + HostFileTransfer(host, UNAME, PWORD, Get_Transfer_List, GET=True) - if Put_Transfer_List: - HostFileTransfer(host, UNAME, PWORD, Put_Transfer_List, GET=False) + if Put_Transfer_List: + HostFileTransfer(host, UNAME, PWORD, Put_Transfer_List, GET=False) - if Commands: - HostCommands(host, UNAME, PWORD, SUDOPW, Commands) + if Commands: + HostCommands(host, UNAME, PWORD, SUDOPW, Commands)