OEM target property update 1
#!/bin/bash
# Define SQL query to fetch host names and support groups
SQL_QUERY="SELECT DISTINCT SUBSTR(name, INSTR(name, '@') + 1) AS host_name, support_group
FROM OEM.CDB_DAILY;"
# 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, fetch associated target types, and update using EMCLI
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 for the current host
SQL_TARGETS="SELECT assoc_target_name, target_type
FROM sysman.mgmt\$target_associations
WHERE assoc_target_name = '$host_name';"
# Execute SQL to get target types for the host
sqlplus -S user/password@your_db <<EOF > /tmp/targets.txt
$SQL_TARGETS
EOF
# Loop through each associated target and run EMCLI command
while IFS=" " read -r assoc_target_name target_type; do
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 $assoc_target_name ($target_type) with support group $support_group"
done < /tmp/targets.txt
done < /tmp/hosts_support_groups.txt
Comments
Post a Comment