Skip to content
Anthony Kiesel edited this page Oct 27, 2017 · 13 revisions

Intro

I originally made this script while taking a class in computer security. In my coursework I was often asked to run a Linux command several times using various different options and to see what changed with different settings.
In order to make this easier, I wrote a quick python script that would take the various options asked for, and run the command several times using those options. This program is based on that original utility.


Usage

Example:

python3 bashForEach.py --cmd "openssl dgst -{1} {0}" --args testFile.txt testFile2.txt --args sha256 sha512 --combos --verbose

Result

Sorry! A little hard to see unless you open the image in a new tab or zoom in! Combo Example

Notes:

For this example, the --combos flag is used. For the combos flag, the program takes each list of arguments and runs every possible combination of those arguments with the provided command. In this example, each file is ran through each hash algorithm to produce multiple hashes per algorithm, per file.

Example 2:

python3 bashForEach.py --cmd "openssl dgst -{1} {0}" --args testFile.txt testFile2.txt --args sha256 sha512 --verbose

Results 2

Sorry! A little hard to see unless you open the image in a new tab or zoom in! Combo Example

Notes 2:

For this example, the --combos flag was NOT used. In this case, the nth element is chosen out of each list and used to build the nth command.

Command line help menu:

usage: bashForEach.py [-h] [--cmd CMD] [--args ARGUMENTLIST [ARGUMENTLIST ...]] [--combos] [-v]

optional arguments:

-h, --help show this help message and exit

--cmd CMD

--args ARGUMENTLIST [ARGUMENTLIST ...]

                    For each set of arguments to be used in the given
                    command, use the --args flag followed by a list of
                    arguments to be used for the nth argument position.
                    ===================================================
                    EX:
                    ===================================================
                    --args fileone.txt filetwo.txt filethree.txt --args
                    someoption_1 someoption_2 someoption_3

--combos
Flag that specifies that Combination Arguments are used instead of Indexed Arguments.

                    ===================================================
                    Indexed Arguments: Each argument list is expected to
                    be the same length. The number of commands is equal to
                    the number of arguments provided in each list. The nth
                    element in all of the argument lists coorelates to the
                    nth command executed. Likewise, the nth argument list
                    contains a list of each option to be ran with the nth
                    argument.
                    ===================================================
                    Combination Arguments: Argument lists can be any
                    length greater than 0. The number of commmands is
                    equal to the number of possible combinations of all
                    argument lists. For each argument list, each option in
                    the list is combined with all possible options from
                    previous argument lists. The nth argument list
                    correlates to the nth argument placeholder index.

-v, --verbose

Clone this wiki locally