diff --git a/tsshbatch.py b/tsshbatch.py index 1e268c2..aa2bb72 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -9,7 +9,7 @@ PROGNAME = "tsshbatch.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tsshbatch.py,v 1.113 2011/11/04 18:38:03 tundra Exp $" +RCSID = "$Id: tsshbatch.py,v 1.114 2011/11/04 19:03:25 tundra Exp $" VERSION = RCSID.split()[2] @@ -30,6 +30,7 @@ import getpass import os import paramiko +import shlex import socket import sys @@ -40,7 +41,7 @@ FAILURE = "FAILURE" INDENTWIDTH = 8 -OPTIONSLIST = "kn:p:" +OPTIONSLIST = "h:kn:p:" PADWIDTH = 30 SEPARATOR = " ---> " SUCCESS = "SUCCESS" @@ -142,15 +143,18 @@ # End of 'PrintReport()' +# ---------------------- Program Entry Point ---------------------- # + ##### -# Program Entry Point +# Process Any Options User Set In The Environment Or On Command Line ##### # Options that can be overriden by user -KEYEXCHANGE = False -PWORD = "" -UNAME = "" +HOSTS = "" # List of hosts to target +KEYEXCHANGE = False # Do key exchange-based auth? +PWORD = "" # Password +UNAME = "" # Login name # Handle any options set in the environment @@ -176,6 +180,9 @@ for opt, val in opts: + if opt == "-h": + HOSTS = val.split() + if opt == "-k": KEYEXCHANGE = True @@ -185,22 +192,9 @@ if opt == "-p": PWORD = val -# Go do the requested work - - -# Get the list of hosts - -try: - f = open(args[0]) - hosts = f.readlines() - f.close() - -except: - ErrorExit(eBADFILE % sys.argv[1]) - -# Create the command - -cmd = " ".join(args[1:]) +##### +# Go Do The Requested Work +##### # If we're not doing key exchange-based authentication, get # user name & password. @@ -217,11 +211,35 @@ PWORD = getpass.getpass(pPASS) +# Host list and command parsing + +# Get the list of hosts if not specified on command line. +# The assumption is that the first argument is the file +# containing the list of targeted hosts and the remaining +# arguments form the command. + +if not HOSTS: + + try: + f = open(args[0]) + HOSTS = f.readlines() + f.close() + + except: + ErrorExit(eBADFILE % sys.argv[1]) + + CMD = " ".join(args[1:]) + +# If hosts were passed on the command line, all the arguments +# are understood to form the command. + +else: + CMD = " ".join(args[0:]) + # Iterate over the list of hosts, executing the command -for host in hosts: +for host in HOSTS: host = host.strip() if host: - HostCommand(host, UNAME, PWORD, cmd) - + HostCommand(host, UNAME, PWORD, CMD)