Reputation: 313
I want to iterate the first line in "profile" to the first line in "arn" and then 2nd line "profile" to 2nd line in "arn", 3rd line in "profile" to 3rd line in "arn"
But my script check the first in profile file and loop all the contents in "arn" file. After finishing it will got to next line in "profile" and loop all the content in "arn"
#!/bin/bash
for profile in `cat ../../.aws/config|grep 'profile'`
do
for arn in `cat policy_arn`
do
aws --profile ${profile} iam delete-policy --policy-arn ${arn}
done
done
cat policy_arn
arn:aws:iam::37928052:policy/PointPolicy
arn:aws:iam::56433041:policy/PointPolicy
arn:aws:iam::18225202:policy/PointPolicy
arn:aws:iam::908231278:policy/PointPolicy
arn:aws:iam::441043922:policy/PointPolicy
arn:aws:iam::227661653:policy/PointPolicy
profile
dev-ops
pro-ops
qc-ops
OUTPUT
should be
first loop arn=arn:aws:iam::37928052:policy/PointPolicy and profile=dev-ops
2. arn=arn:aws:iam::56433041:policy/PointPolicy profile=pro-ops
3. arn=arn:aws:iam::18225202:policy/PointPolicy profile=qc-ops
But what is happening when i run the script is
dev-ops arn:aws:iam::37928052:policy/PointPolicy
dev-ops arn:aws:iam::56433041:policy/PointPolicy
dev-ops arn:aws:iam::18225202:policy/PointPolicy
dev-ops arn:aws:iam::908231278:policy/PointPolicy
dev-ops arn:aws:iam::441043922:policy/PointPolicy
dev-ops arn:aws:iam::227661653:policy/PointPolicy
pro-ops arn:aws:iam::37928052:policy/PointPolicy
pro-ops arn:aws:iam::56433041:policy/PointPolicy
pro-ops arn:aws:iam::18225202:policy/PointPolicy
pro-ops arn:aws:iam::908231278:policy/PointPolicy
pro-ops arn:aws:iam::441043922:policy/PointPolicy
pro-ops arn:aws:iam::227661653:policy/PointPolicy
qc-ops arn:aws:iam::37928052:policy/PointPolicy
qc-ops arn:aws:iam::56433041:policy/PointPolicy
qc-ops arn:aws:iam::18225202:policy/PointPolicy
qc-ops arn:aws:iam::908231278:policy/PointPolicy
qc-ops arn:aws:iam::441043922:policy/PointPolicy
qc-ops arn:aws:iam::227661653:policy/PointPolicy
I have 40+ aws accounts so i will create a loop for "profile" at the same time policy arn should get with the same profile account ID.
How can I achieve the output like this.
Upvotes: 1
Views: 158
Reputation: 2784
You can do this with:
grep 'profile' ../../.aws/config | paste - policy_arn
The paste
command joins two files as columns, and here we use -
for the first filename to represent it coming from stdin
(ie it comes from the pipe). No loop is required.
Upvotes: 3