oracle / oracle/oci-cli

Running OCI command in bash script not working

Open
#574 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
669
Forks
236
Avg merge
1m
Merged PRs (30d)
4

Description

Following bash script

#!/bin/bash
LSL=$(oci iam compartment list  | jq .data[].id)

declare -a ARRAY
ARRAY=($LSL)

for i in "${ARRAY[@]}"; do
  echo "RUNNING: oci compute instance list -c $i | jq '.data[].\"display-name\"'"
  oci compute instance list -c $i | jq '.data[]."display-name"'  
done

I get the following error:

RUNNING: oci compute instance list -c "ocid1.compartment...." | jq '.data[]."display-name"'
ServiceError:
{
    "code": "InvalidParameter",
    "message": "Invalid compartmentId. Please visit https://docs.oracle.com/en-us/iaas/Content/API/References/apierrors.htm to learn more about this error code",
    "opc-request-id": "...",
    "status": 400
}

However when I run the command manually it works without problem.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied bash script and compare the compartment IDs it passes to oci compute instance list -c with a manual invocation. Trace the values assigned to ARRAY and verify the looped command produces instance display names without the reported InvalidParameter error; done means the scripted invocation succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash
Domain
cli, cloud, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.