diff --git a/tsshbatch.py b/tsshbatch.py index 9f9402d..a9faea5 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.140 2013/10/20 23:00:29 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.141 2013/10/21 00:03:33 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" @@ -61,7 +61,7 @@ COMMENT = "#" FAILURE = "FAILURE: %s" INDENTWIDTH = 8 -OPTIONSLIST = "H:Nehkn:p:v" +OPTIONSLIST = "G:H:NP:ehkn:p:v" PADWIDTH = 30 SEPERATOR = " ---> " SUCCESS = "SUCCESS" @@ -72,17 +72,19 @@ USAGE = \ PROGVER + "\n" +\ HOMEPAGE + "\n\n" +\ - "Usage: tsshbatch.py [-Nehkv] [-n name] [-p pw] [-H 'host host ..' | serverlistfile] command arg arg arg \n" +\ + "Usage: tsshbatch.py [-Nehkv] [-n name] [-p pw] -G 'file dest' -P 'file dest' [-H 'host ..' | serverlistfile] command arg ... \n" +\ " where,\n" +\ "\n" +\ - " -H '...' List of targeted hosts passed as a single argument\n" +\ - " -N Force prompting for username\n" +\ - " -e Don't report remote host stderr output\n" +\ - " -h Display help\n" +\ - " -k Use key exchange-based authentication\n" +\ - " -n name Specify login name\n" +\ - " -p pw Specify login password\n" +\ - " -v Display extended program version information\n" + " -G 'file dest' GET file on host and write local dest\n" +\ + " -H '...' List of targeted hosts passed as a single argument\n" +\ + " -N Force prompting for username\n" +\ + " -P 'file dest' PUT local file to host dest\n" +\ + " -e Don't report remote host stderr output\n" +\ + " -h Display help\n" +\ + " -k Use key exchange-based authentication\n" +\ + " -n name Specify login name\n" +\ + " -p pw Specify login password\n" +\ + " -v Display extended program version information\n" ##### # Error Messages @@ -91,8 +93,10 @@ eBADARG = "Invalid command line: %s!" eBADFILE = "Cannot open '%s'!" eBADSUDO = "sudo Failed, Check Password Or Command! sudo Error Report: %s" +eBADTXRQ = "Bad Transfer Request: %s Must Have Exactly 1 Source And 1 Destination!" eFXERROR = "File Transfer Error While Attempting %s: %s" eNOCONNECT = "Cannot Connect: %s" +eNOHOSTS = "No Hosts Specified!" eNOLOGIN = "Cannot Login! (Login/Password Bad?)" @@ -138,7 +142,7 @@ ##### -# Tranfer Files To A Host +# Transfer Files To A Host ##### def HostFileTransfer(host, user, pw, filelist): @@ -263,6 +267,27 @@ # End of 'PrintReport()' +##### +# Process A File Transfer Request +##### + +def ProcessTXRQ(request, storage): + + src_dest = request.split() + if len(src_dest) != 2: + ErrorExit(eBADTXRQ % src_dest) + + else: + + if src_dest[0] not in storage: + storage[src_dest[0]] = [src_dest[1],] + + else: + storage[src_dest[0]].append(src_dest[1]) + +# End of 'ProcessTXRQ' + + # ---------------------- Program Entry Point ---------------------- # ##### @@ -280,7 +305,9 @@ # Place To Keep File Transfer Requests -File_Transfer_List ={} +Put_Transfer_List = {} +Get_Transfer_List = {} + # Handle any options set in the environment @@ -297,15 +324,20 @@ opts, args = getopt.getopt(OPTIONS, OPTIONSLIST) except getopt.GetoptError, (errmsg, badarg): ErrorExit(eBADARG % errmsg) - for opt, val in opts: + if opt == "-G": + ProcessTXRQ(val, Get_Transfer_List) + if opt == "-H": HOSTS = val.split() if opt == "-N": PROMPTUSERNAME = True + if opt == "-P": + ProcessTXRQ(val, Put_Transfer_List) + if opt == "-e": REPORTERR = False @@ -370,13 +402,20 @@ if not HOSTS: + # Even if we are only doing file transfers and no command + # is specified, we have to have at least one argument here + # to tell us what hosts we're working on. + + if not args: + ErrorExit(eNOHOSTS) + try: f = open(args[0]) HOSTS = f.readlines() f.close() except: - ErrorExit(eBADFILE % sys.argv[1]) + ErrorExit(eBADFILE % args[0]) CMD = " ".join(args[1:]) @@ -395,17 +434,16 @@ if CMD.startswith(SUDO) and not PWORD: PWORD = getpass.getpass(pSUDO) -# Iterate over the list of hosts, executing the command. -# Accomodate commenting out hosts in a list. +# Iterate over the list of hosts, executing any file transfers and +# commands. Accomodate commenting out hosts in a list. for host in HOSTS: host = host.split(COMMENT)[0].strip() if host: - - if File_Transfer_List: - HostFileTransfer(host, UNAME, PWORD, File_Transfer_List) - + + print Get_Transfer_List + print Put_Transfer_List if CMD: HostCommand(host, UNAME, PWORD, CMD)