I had a small script where I would source into each openstack's tenant and fetch some output with the help of python. It took too long for the reports to get generated and I was suggested to use xargs
. My earlier code was like below.
#!/bin/bash
cd /scripts/cloud01/floating_list
rm -rf ./reports/openstack_reports/
mkdir -p ./reports/openstack_reports/
source ../creds/base
for tenant in A B C D E F G H I J K L M N O P Q R S T
do
source ../creds/$tenant
python ../tools/openstack_resource_list.py > ./reports/openstack_reports/$tenant.html
done
lftp -f ./lftp_script
Now I have put xargs in the script and the script looks something like this.
#!/bin/bash
cd /scripts/cloud01/floating_list
rm -rf ./reports/openstack_reports/
mkdir -p ./reports/openstack_reports/
source ../creds/base
# Need xargs idea below
cat tenants_list.txt | xargs -P 8 -I '{}' # something that takes the tenant name and source
TENANT_NAME={}
python ../tools/openstack_resource_list.py > ./reports/openstack_reports/$tenant.html
lftp -f ./lftp_script
In this script how am I supposed to implement source ../creds/$tenant
? Because while each tenant is dealt with, it needs to be sourced as well and I am not sure how to include that with xargs for parallel execution.