diff --git a/TODO b/TODO index ebf0ea6..8a5e702 100644 --- a/TODO +++ b/TODO @@ -24,6 +24,22 @@ convenient for external programs to make use of those inventory features. + - The -F "string ..." option will examine every file on the host- + or command paths, looking for matching strings within these files. + Matches will report the file name, the location within the file, + and the line containing any of the specified strings. + + This is a simple, case-insensitive string literal match and does + not support regular expressions. + + This is handy when you're looking for a host name or command + string, say like, "sudo", and you don't want to have to manually + go through all your support files. + + - The -V "string ..." option does the exact opposite of -F. It + lists all the files that do NOT contain any of the specified + strings. + [CHANGES] diff --git a/tsshbatch.py b/tsshbatch.py index 722510f..9384f5b 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -14,7 +14,7 @@ # Version Information - Overwritten by makefile during release process ##### -GITID = '664e4d0 tundra Fri Sep 30 17:29:41 2016 -0500' +GITID = '96d0925 tundra Fri Sep 30 18:16:51 2016 -0500' VERSION = '1.311' @@ -87,7 +87,8 @@ HOSTNOISE = '[%s]' HOSTLIST = 'Hosts' INDENTWIDTH = 8 -OPTIONSLIST = 'BC:EG:H:KLNP:ST:Wabef:hi:kl:n:p:qstvxy' +NOMATCH = "No string matches!" +OPTIONSLIST = 'BC:EF:G:H:KLNP:ST:V:Wabef:hi:kl:n:p:qstvxy' PADWIDTH = 12 PATHDELIM = ':' PATHSEP = os.sep @@ -106,12 +107,13 @@ USAGE = \ PROGVER + "\n" +\ HOMEPAGE + "\n\n" +\ - "Usage: tsshbatch.py [-BEKLNSTWaehkqstvy -C configfile -G 'file dest' -P 'file dest' -f cmdfile -l logfile -n name -p pw ] -H 'host ..' -i 'hostfile ...' [command arg ... ]\n" +\ + "Usage: tsshbatch.py [-BEF:KLNSTVWaehkqstvy -C configfile -G 'file dest' -P 'file dest' -f cmdfile -l logfile -n name -p pw ] -H 'host ..' -i 'hostfile ...' [command arg ... ]\n" +\ " where,\n" +\ "\n" +\ " -B Print start and stop statistics (Off)\n" +\ " -C configfile Specify location of ssh configuration file (~/.ssh/config)\n" +\ " -E Write error output to stdout instead of stderr (Output to stderr)\n" +\ + " -F 'string ...' Examine host- and command files for matching strings\n" +\ " -K Force password prompting - Overrides previous -k\n" +\ " -G 'file dest' GET file on host and write local dest directory\n" +\ " -H '...' List of targeted hosts passed as a single argument\n" +\ @@ -120,6 +122,7 @@ " -P 'file dest' PUT local file to host dest directory\n" +\ " -S Force prompting for sudo password\n" +\ " -T seconds Timeout for ssh connection attempts (15 sec)\n" +\ + " -V 'string ...' Examine host- and command files without matching strings\n" +\ " -W Write list of hosts to stdout and exit\n" +\ " -a Don't abort program after failed file transfers (Abort on failure)\n" +\ " -b Don't abort program after failed sudo command (Abort on failure)\n" +\ @@ -871,6 +874,39 @@ if opt == "-E": REDIRSTDERR = True + if ( opt == "-F" or opt == "-V"): + + # Look for string matches or misses in + # the host- and command files + + files = FindFilesOnPath(HOSTINCL) + files += FindFilesOnPath(CMDINCL) + + for fn in files: + f = open(fn, 'r') + content = f.readlines() + f.close() + + linenum = 0 + matched = False + for line in content: + + linenum += 1 + for string in val.split(): + if string.lower() in line.lower(): + if opt == "-F": + PrintStdout("%s:%s %s" % (fn, linenum, line.strip())) + matched = True + break + + # Handle non-matches if we asked for that + + if (not matched and opt == '-V'): + PrintStdout("%s: %s" % (fn, NOMATCH)) + + + sys.exit() + if opt == "-K": KEYEXCHANGE = False @@ -881,10 +917,14 @@ Hosts += val.split() if opt == "-L": + + # List all the host- and command files + for hdr, pathenv in [[iHOSTFILES, HOSTINCL], [iCMDFILES, CMDINCL]]: PrintStdout(hdr) PrintStdout("\n".join(FindFilesOnPath(pathenv)), EOL="\n\n") + sys.exit() if opt == "-N": diff --git a/tsshbatch.rst b/tsshbatch.rst index 885bd57..d7f892c 100644 --- a/tsshbatch.rst +++ b/tsshbatch.rst @@ -80,6 +80,20 @@ ``2>&1 | ...` on the command line when you want to pipe all ``tsshbatch`` output to another program. + -F strings This will examine every file on the host- or + command paths, looking for matching strings within + these files. Matches will report the file name, + the location within the file, and the line + containing any of the specified strings. + + This is a simple, case-insensitive string literal + match and does not support regular expressions. + + This is handy when you're looking for a host name + or command string, say like, ``sudo`` and you don't + want to have to manually go through all your + support files. + -K Force prompting for passwords. This is used to override a prior ``-k`` argument. @@ -132,6 +146,10 @@ -T seconds Set timeout for ssh connection attempts. (Default: 15 seconds) + -V strings Similar to the ``-F`` command but with the inverse logic. + Reports the names of all host- and command files that + do not contain any of the specified strings. + -W Print out a single line list of the inventory that would be processed and exit. (Test mode only - Ignored in execution mode.) @@ -1262,7 +1280,7 @@ :: - $Id: '664e4d0 tundra Fri Sep 30 17:29:41 2016 -0500' + $Id: '96d0925 tundra Fri Sep 30 18:16:51 2016 -0500' This document was produced with ``emacs``, ``RestructuredText``, and ``TeX Live``.