OEM blackout create

#!/bin/bash


# Get ASM SID

export ORACLE_SID=$(ps -ef | grep '[a]sm_smon.*+ASM' | awk '{print $NF}' | cut -d '_' -f3)

source oraenv <<< "$ORACLE_SID"


# Get cluster nodes

CLUSTER_NODES=$(olsnodes | tr '\n' ',' | sed 's/,$//')


# Dynamic time input

read -p "Enter start time (YYYY-MM-DD HH:MM): " start_time

read -p "Enter duration (HH:MM): " duration


# Transform cluster nodes into required format

TARGETS=$(echo $CLUSTER_NODES | tr ',' '\n' | awk '{print $1".x.com:host;"}' | tr -d ' ')


# Set blackout name

BLACKOUT_NAME="Test_NotificationBlackout_xxxx"


# Set blackout reason

BLACKOUT_REASON="Database Patch/Maintenance"


# Construct the EMCLI command

emcli_cmd="/emcli create_blackout -name=\"$BLACKOUT_NAME\" -reason=\"$BLACKOUT_REASON\" -add_targets=\"$TARGETS\" -schedule=\"frequency:once;start_time:$start_time;duration:$duration;tzinfo:target;tzoffset:1\""


# Print EMCLI command

echo "Executing EMCLI command: $emcli_cmd"


# Execute the EMCLI command with error handling

if $emcli_cmd; then

  echo "Blackout creation completed."

else

  echo "Error: EMCLI command failed."

fi



*************

#!/bin/bash


# Ensure script safety with strict error handling

set -e


# Dynamic time input

read -p "Enter cluster_name (frame_cluser): " cluster_name

read -p "Enter start time (YYYY-MM-DD HH:MM): " start_time

read -p "Enter duration (HH:MM): " duration


# Set blackout name dynamically

BLACKOUT_NAME="NotificationBlackout_$cluster_name"


# Set blackout reason

BLACKOUT_REASON="Database Patch/Maintenance"


# Construct targets based on cluster name (assuming cluster-wide blackout)

TARGETS="$cluster_name:cluster"


# Construct the EMCLI command

emcli_cmd="./emcli create_blackout -name=\"$BLACKOUT_NAME\" -reason=\"$BLACKOUT_REASON\" -add_targets=\"$TARGETS\" -schedule=\"frequency:once; start_time:$start_time; duration:$duration; tzinfo:target; tzoffset:1\""


# Print EMCLI command

echo "Executing EMCLI command: $emcli_cmd"


# Execute the EMCLI command (missing in the original code)

$emcli_cmd || echo "Error: EMCLI command failed."


# Post-patching commands (replace hardcoded name with dynamic variable)

emcli_cmd_stop_blackout="./emcli stop_blackout -name=\"$BLACKOUT_NAME\""

emcli_cmd_delete_blackout="./emcli delete_blackout -name=\"$BLACKOUT_NAME\""


# Execute the post-patching commands (missing in the original code)

$emcli_cmd_stop_blackout || echo "Error: EMCLI stop_blackout command failed."

$emcli_cmd_delete_blackout || echo "Error: EMCLI delete_blackout command failed."


Comments

Popular posts from this blog

SQL Loader V3

Db Unix

Standby redo log add