'using python, get a list of directories for parallel script execution
I need to be able to get a list of directories with the following pattern:
/app/{APP_NAME}/current/bin
in order to run start and stop scripts. The problem I run into is that, depending on the node, there could be between one and 22 such directories on any given node, and I need a "generic" means to get all these directories into a list and run the stop or start scripts within them in parallel.
Solution 1:[1]
Sounds like a globbing problem.
First let's make bunch of dirs in the same-ish hierarchy as you want.
mkdir -p /tmp/so/app/{1,2,3,4}/current/bin
Then we can go find them in python.
import glob
bindirs = glob.glob("/tmp/so/app/*/current/bin")
print(bindirs)
>>> ['/tmp/so/app/1/current/bin', '/tmp/so/app/4/current/bin', '/tmp/so/app/3/current/bin', '/tmp/so/app/2/current/bin']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ljmc |