OEM target property update 3

 #!/bin/bash


# Define SQL query to fetch host and support group from CMDB

SQL_QUERY="SELECT DISTINCT SUBSTR(name, INSTR(name, '@') + 1) AS host_name, support_group 

           FROM OEM_ADMIN.CMDCDAILY;"


# Execute SQL and store results in a temporary file

sqlplus -S user/password@your_db <<EOF > /tmp/hosts_support_groups.txt

$SQL_QUERY

EOF


# Loop through each host and support group from the query result

while IFS=" " read -r host_name support_group; do

  # Skip header or empty lines

  if [[ "$host_name" == "HOST_NAME" || -z "$host_name" ]]; then

    continue

  fi

  

  # SQL query to fetch associated target types (oracle_database, rac_database, host, agent, listener) for the host

  SQL_TARGETS="SELECT assoc_target_name, target_type 

               FROM sysman.mgmt\$target_associations 

               WHERE assoc_target_name = '$host_name';"

  

  # Execute SQL to get associated targets

  sqlplus -S user/password@your_db <<EOF > /tmp/targets.txt

  $SQL_TARGETS

EOF


  # Loop through each target associated with the host

  while IFS=" " read -r assoc_target_name target_type; do

    # Skip header or empty lines

    if [[ "$assoc_target_name" == "ASSOC_TARGET_NAME" || -z "$assoc_target_name" ]]; then

      continue

    fi

    

    # Run EMCLI to update the orcl_gtp_contact property for the target

    emcli modify_target -name="$assoc_target_name" \

                        -type="$target_type" \

                        -properties="orcl_gtp_contact->$support_group" \

                        -separator-properties="|" \

                        -subseparator-properties="->" \

                        -on_agent


    echo "Updated orcl_gtp_contact for $assoc_target_name ($target_type) with support group $support_group"


  done < /tmp/targets.txt

  

done < /tmp/hosts_support_groups.txt

Comments

Popular posts from this blog

SQL Loader V3

Db Unix

Standby redo log add