Demo OEM module

 #!/bin/bash


# Set environment variables

DB_USER="user"

DB_PASS="password"

DB_CONN="your_db"

SQLPLUS="sqlplus -S $DB_USER/$DB_PASS@$DB_CONN"

TEMP_FILE="/tmp/hosts_support_groups.txt"


# Step 1: Fetch distinct host and support group for updating 'orcl_gtp_contact'

SQL_QUERY_SUPPORT_GROUP="SELECT DISTINCT SUBSTR(name, INSTR(name, '@') + 1) AS host_name, support_group FROM OEM_ADMIN.CMDB_DB_CI_DAILY;"


# Execute SQL query for support group and store in a file

$SQLPLUS <<EOF > $TEMP_FILE

$SQL_QUERY_SUPPORT_GROUP

EOF


# Step 2: Process Support Group from the file and generate EMCLI commands

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


  # 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 and store in a temporary file

  $SQLPLUS <<EOF > /tmp/associated_targets.txt

  $SQL_TARGETS

  EOF

  

  # Loop through each associated target and update 'orcl_gtp_contact'

  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

    

    # Generate the appropriate EMCLI command

    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) to $support_group"

  done 

< /tmp/associated_targets.txt

done < $TEMP_FILE

Comments

Popular posts from this blog

SQL Loader V3

Db Unix

Standby redo log add