- 新しい順
- 投票が多い順
- コメントが多い順
Swap those backticks (`) for single quotes ('). Backticks try to execute the command within them, while single quotes just store the literal text. Wrap the entire aws organizations command in $( ) for proper command substitution. It pipes the command output directly into the variable. Assign the output directly to parent_ou within the for loop, like this:
for account in $(aws organizations list-accounts --query 'Accounts[].Id' --output text); do
echo "$account"
parent_ou=$(aws organizations list-parents --child-id "$account" --query Parents[*].Id --output text)
echo "$parent_ou"
done
Consider using command chaining with | for even cleaner code
for account in $(aws organizations list-accounts --query 'Accounts[].Id' --output text); do
echo "$account"
parent_ou=$(aws organizations list-parents --child-id "$account" --query Parents[*].Id --output text | tr -d '\n')
echo "$parent_ou"
done
Hello,
Your script has 2 points to modify.
b_ous = `aws organizations list-organization-units-for-parent --parent-id o_hhhhh_**** --query OrganizationalUnits[*].Id --output text`
- sub command is "list-organizational-units-for-parent"
aws organizations list-organizational-units-for-parent
- list-organizational-units-for-parent --parent-id option should handle Root "r-" or OU "ou-", not Organization "o-"
OPTIONS
--parent-id (string)
The unique identifier (ID) of the root or OU whose child OUs you
want to list.
The regex pattern for a parent ID string requires one of the
following:
o Root - A string that begins with "r-" followed by from 4 to 32
lowercase letters or digits.
o Organizational unit (OU) - A string that begins with "ou-"
followed by from 4 to 32 lowercase letters or digits (the ID of
the root that the OU is in). This string is followed by a second
"-" dash and from 8 to 32 additional lowercase letters or digits.
Hello.
I executed the shell script below using CloudShell and it was executed successfully.
I can't reproduce the same error as you.
Is it possible for you to share the entire shell script?
#!/bin/bash
for account in $(aws organizations list-accounts --query 'Accounts[].Id' --output text); do
echo $account
parent_ou=`aws organizations list-parents --child-id $account --query Parents[*].Id --output text`
echo $parent_ou
done
strange. Yes, the exact command works fine on my terminal, just the bash assignment fails. Thanks for for taking a look.
関連するコンテンツ
- AWS公式更新しました 2年前
You can drop the double quotes around the variables your echoing too