OCI CLI to list all the database and its host lifecycle - Enahanced
This shell script can be used, though tenancy ocid id should be updated with the actual one.
ociCompartmentList=$(oci iam compartment list --compartment-id ocid1.tenancy.oc1..aaaa1111222334)
for c in $(echo "$ociCompartmentList" | jq '.data | keys | .[]')
do
compartment_ocid=$(echo "$ociCompartmentList" | jq -r ".data[$c].\"id\"")
ocidbList=$(oci db database list -c $compartment_ocid)
for i in $(echo "$ocidbList" | jq '.data | keys | .[]')
do
dbname=$(echo "$ocidbList" | jq -r ".data[$i].\"db-name\"")
dbsystemid=$(echo "$ocidbList" | jq -r ".data[$i].\"db-system-id\"")
lifecycle=$(echo "$ocidbList" | jq -r ".data[$i].\"lifecycle-state\"")
dbNodeList=$(oci db node list -c $compartment_ocid --db-system-id $dbsystemid)
for n in $(echo "$dbNodeList" | jq '.data | keys | .[]')
do
hostname=$(echo "$dbNodeList" | jq -r ".data[$n].\"hostname\"")
host_ocid=$(echo "$dbNodeList" | jq -r ".data[$n].\"id\"")
host_lifcycle=$(echo "$dbNodeList" | jq -r ".data[$n].\"lifecycle-state\"")
vnic=$(echo "$dbNodeList" | jq -r ".data[$n].\"vnic-id\"")
public_ip=$(oci network vnic get --vnic-id ${vnic} | jq -r ".data[\"public-ip\"]")
echo "Hostname: ${hostname}(${public_ip}) | HostLifeCycle: ${host_lifcycle} | Database: $dbname | DBLifeCycle: $lifecycle"
done
done
done
for c in $(echo "$ociCompartmentList" | jq '.data | keys | .[]')
do
compartment_ocid=$(echo "$ociCompartmentList" | jq -r ".data[$c].\"id\"")
ocidbList=$(oci db database list -c $compartment_ocid)
for i in $(echo "$ocidbList" | jq '.data | keys | .[]')
do
dbname=$(echo "$ocidbList" | jq -r ".data[$i].\"db-name\"")
dbsystemid=$(echo "$ocidbList" | jq -r ".data[$i].\"db-system-id\"")
lifecycle=$(echo "$ocidbList" | jq -r ".data[$i].\"lifecycle-state\"")
dbNodeList=$(oci db node list -c $compartment_ocid --db-system-id $dbsystemid)
for n in $(echo "$dbNodeList" | jq '.data | keys | .[]')
do
hostname=$(echo "$dbNodeList" | jq -r ".data[$n].\"hostname\"")
host_ocid=$(echo "$dbNodeList" | jq -r ".data[$n].\"id\"")
host_lifcycle=$(echo "$dbNodeList" | jq -r ".data[$n].\"lifecycle-state\"")
vnic=$(echo "$dbNodeList" | jq -r ".data[$n].\"vnic-id\"")
public_ip=$(oci network vnic get --vnic-id ${vnic} | jq -r ".data[\"public-ip\"]")
echo "Hostname: ${hostname}(${public_ip}) | HostLifeCycle: ${host_lifcycle} | Database: $dbname | DBLifeCycle: $lifecycle"
done
done
done
This script list for a specific compartment, only. In this script, please update compartment OCID with the actual one.:
compartment_ocid="ocid1.compartment.oc1..aaaaaa..8dfh8ea"
ocidbList=$(oci db database list -c $compartment_ocid)
for i in $(echo "$ocidbList" | jq '.data | keys | .[]')
do
dbname=$(echo "$ocidbList" | jq -r ".data[$i].\"db-name\"")
dbsystemid=$(echo "$ocidbList" | jq -r ".data[$i].\"db-system-id\"")
lifecycle=$(echo "$ocidbList" | jq -r ".data[$i].\"lifecycle-state\"")
dbNodeList=$(oci db node list -c $compartment_ocid --db-system-id $dbsystemid)
for n in $(echo "$dbNodeList" | jq '.data | keys | .[]')
do
hostname=$(echo "$dbNodeList" | jq -r ".data[$n].\"hostname\"")
host_ocid=$(echo "$dbNodeList" | jq -r ".data[$n].\"id\"")
host_lifcycle=$(echo "$dbNodeList" | jq -r ".data[$n].\"lifecycle-state\"")
vnic=$(echo "$dbNodeList" | jq -r ".data[$n].\"vnic-id\"")
public_ip=$(oci network vnic get --vnic-id ${vnic} | jq -r ".data[\"public-ip\"]")
echo "Hostname: ${hostname}(${public_ip}) | HostLifeCycle: ${host_lifcycle} | Database: $dbname | DBLifeCycle: $lifecycle"
done
done
Reference: Original script used from Senthil Rajendra's Blog and enhanced to my needs to list all RAC nodes and list public IP associated.