Posts

Showing posts from February, 2024

Golden gate stop v1

#!/bin/bash read -p "Enter the log directory: " log_dir if [ -z "$log_dir" ]; then     echo "Log directory not provided. Exiting."     exit 1 fi mkdir -p "$log_dir" for value in $(locate setup_ogg | grep -E '/setup_ogg$'); do     source $value     cp $value $value_prepatch_bkp'$(date +"%Y%m%d%H%M%S")'     GG_HOME=$(dirname "$value")     GG_HOME_FILE=$(echo "$GG_HOME" | tr '/' '_')     log_file="$log_dir/gg_info_$GG_HOME_FILE.log"     cd "$GG_HOME"     echo "==cccccces === ============" > "$log_file"     echo "Executing 'info all' in $GG_HOME" >> "$log_file"     ./ggsci <<EOF >> "$log_file"     STOP ER * detail EOF done # Capture the log without the header export ORACLE_SID=$(ps -ef | grep '[a]sm_smon.*+ASM' | awk '{print $NF}' | cut -d '_' -f3) source oraenv <&l

Oratab Entries validate and add

#!/bin/bash # Ask user for log directory read -p "Enter the log directory: " log_directory log_directory=$(realpath "$log_directory") # Ask user for file2 (sop.conf) name read -p "Enter the name of sop.conf file: " file2_name file2_path="$log_directory/$file2_name" # Phase 1: Generate db_unique_name_version.log for SID in $(ps -ef | grep '[o]ra_smon' | awk '{print $NF}' | cut -d '_' -f3); do     export ORACLE_SID=$SID     source oraenv <<< "$SID"     # Get DB unique name and version using the first query     DB_UNIQUE_NAME_INFO=$(sqlplus -s / as sysdba <<EOF set feedback off set heading off SELECT d.DB_UNIQUE_NAME || ':' || SUBSTR(i.VERSION, 1, 2) FROM v\$database d, v\$instance i; EOF     )     # Get instance name and version using the second query     INSTANCE_NAME_INFO=$(sqlplus -s / as sysdba <<EOF set feedback off set heading off SELECT i.INSTANCE_NAME || ':' || SUBSTR(i.

Data guard sync status

#!/bin/bash LOG_DIR="/path/to/log/files" # Loop through all Oracle SIDs for SID in $(ps -ef | grep '[o]ra_smon' | awk '{print $NF}' | cut -d '_' -f3); do     export ORACLE_SID=$SID     dgmgrl / <<EOF > $LOG_DIR/DR_log_config_$SID.txt     show configuration EOF     # Check if Data Guard configuration is not available     if grep -qE "ORA-16525" $LOG_DIR/DR_log_config_$SID.txt; then         echo "Data Guard not available for $SID" > $LOG_DIR/DR_log_all_databases.txt         continue     fi     DB_NAME=$(grep -E "Standby|Physical" $LOG_DIR/DR_log_config_$SID.txt | awk '{print $1}')     dgmgrl / <<EOF > $LOG_DIR/DR_log_status_$DB_NAME.txt     show database "$DB_NAME" EOF     TRANSPORT_LAG=$(cat $LOG_DIR/DR_log_status_$DB_NAME.txt | grep -E "Transport Lag" | awk '{print $4}')     APPLY_LAG=$(cat $LOG_DIR/DR_log_status_$DB_NAME.txt | grep -E "Apply Lag" | awk 

Golden gate stop

 #!/bin/bash # Ask the user for the log directory read -p "Enter the log directory: " log_dir # Check if the log directory is provided if [ -z "$log_dir" ]; then   echo "Log directory not provided. Exiting."   exit 1 fi # Create log directory if it doesn't exist mkdir -p "$log_dir" # Get the list of running Goldengate instances instances=$(agctl status goldengate | grep "is running") # Loop through each line of the output while read -r line; do   # Extract information from each line   manager_name=$(echo "$line" | awk '{print $3}')   node=$(echo "$line" | awk '{print $NF}')   # Create a unique log file for each Oracle home   log_file="$log_dir/gg_stop_$manager_name.log"   # SSH to the respective node and stop Oracle GoldenGate Manager   ssh $node "agctl stop goldengate $manager_name" >> "$log_file" 2>&1 done <<< "$instances"

Acfs status and stop

#!/bin/bash # Prompt for log directory read -p "Enter the log directory path: " log_directory # Create the log directory if it doesn't exist mkdir -p "$log_directory" # Log file path log_file="$log_directory/acfs_script_log_$(date '+%Y%m%d_%H%M%S').log" # Redirect all output to the log file exec > "$log_file" 2>&1 echo "Script started at $(date)" # To stop ACFS replication for value in $(df -kh | grep gg | awk '{print $NF}' | sed -n '2p'); do     acfsutil repl info -c "$value"     acfsutil repl bg stop "$value"     if [ $? -eq 0 ]; then         echo "ACFS replication stopped for $value"     fi done # To stop the filesystem for value in $(df -kh | grep gg | awk '{print $1}' | sed -n '2p'); do     srvctl status filesystem -d "$value"     srvctl stop filesystem -d "$value"     if [ $? -ne 0 ]; then         echo "Issues stopping file

Golden gate capture details

#1/bin/bash #Ask the user for the log directory read -p "Enter the log directory: " log_dir #Check if the log directory is provided if [ -z "$log_dir" ]; then echo "Log directory not provided. Exiting." exit 1 fi #Create log directory if it doesn't exist mkdir -p "$log_dir" #Loop through files named exactly setup_ogg and execute ggsci commands for value in $(locate setup_ogg | grep -E '/setup_ogg$'); do source $value # Extract Oracle GoldenGate home GG_HOME=$(dirname "$value") # Replace "/" with "" in GG_HOME to create a valid filename GG_HOME_FILE=$(echo "$GG_HOME" | tr '/' '_') #Create a unique log file for each Oracle home log_file="$log_dir/gg_info_$GG_HOME_FILE.log" #Change to Oracle GoldenGate home cd "$GG_HOME" # Print a separator in the log file for better readability echo "======________________==================" > "$log_file"

Golden gate v1

 # Loop through setup_ogg files and execute ggsci commands for value in $(locate setup_ogg); do   source $value   # Extract Oracle GoldenGate home   GG_HOME=$(dirname "$value")   # Change to Oracle GoldenGate home   cd $GG_HOME   # Get information about all processes (including ABENDED)   all_processes=$(./ggsci -S <<EOF   INFO ALL   EOF   )   # Check for ABENDED processes   abended_processes=$(echo "$all_processes" | grep ABENDED)   # Display information about all processes   echo "All Processes in $GG_HOME:"   echo "$all_processes"   # Check for and report ABENDED processes   if [ -z "$abended_processes" ]; then     echo "No ABENDED processes found for $GG_HOME."   else     echo "The following processes are ABENDED for $GG_HOME:"     echo "$abended_processes"     echo "Manual Intervention is needed for the process"   fi   # Stopping running processes (excluding ABENDED)   ./ggsci -S <&l

Golden gate v0

 #!/bin/bash # Source Oracle GoldenGate home source /path/to/ogg/home # Check if Oracle GoldenGate home is sourced successfully if [ $? -eq 0 ]; then   echo "Oracle GoldenGate home sourced successfully." else   echo "Failed to source Oracle GoldenGate home. Please check the path."   exit 1 fi # Get information about all processes (including ABENDED) all_processes=$(ggsci <<EOF INFO ALL EOF ) # Check for ABENDED processes abended_processes=$(echo "$all_processes" | grep ABENDED) # Display information about all processes echo "All Processes:" echo "$all_processes" # Check for and report ABENDED processes if [[ -z "$abended_processes" ]]; then   echo "No ABENDED processes found." else   echo "The following processes are ABENDED:"   echo "$abended_processes" fi # Check if any processes are running (excluding ABENDED) running_processes=$(echo "$all_processes" | grep -v ABENDED | grep -v

Create restore point

#!/bin/bash # Set OUTPUT_DIRECTORY and SCRIPTS_DIRECTORY OUTPUT_DIRECTORY="/path/to/your/output_directory" SCRIPTS_DIRECTORY="/path/to/your/scripts_directory" # Function to execute restore.sh create_restore_point() {     # Call restore.sh with arguments     sh restore.sh "$OUTPUT_DIRECTORY" "$SCRIPTS_DIRECTORY" } # Call the function using log_output log_output "Capture Listener Info" "create_restore_point" ******** #!/bin/bash # Set OUTPUT_DIRECTORY and SCRIPTS_DIRECTORY from the first and second command-line arguments OUTPUT_DIRECTORY="$1" SCRIPTS_DIRECTORY="$2" # ... (other code) # Function to create a restore point create_restore_point() {     # Note: Not applicable for STANDBY's as it creates GRP on Primary if running any.     echo "Note: Not applicable for STANDBY's as it creates GRP on Primary if running any."     # Create Restore Point     echo "CREATE RESTORE POINT <name>

Scan listener relocate

#!/bin/bash # ... (other code) # Function to run post_patch_relocate.sh script run_post_patch_relocate() {     local OUTPUT_DIRECTORY="$1"     # Run post_patch_relocate.sh with default 'n' option     log_output "Post Patch Relocate" "sh post_patch_relocate.sh \"$OUTPUT_DIRECTORY\" <<EOF n EOF" } # ... (other code) # Call the function with the OUTPUT_DIRECTORY variable run_post_patch_relocate "$OUTPUT_DIRECTORY" # ... (other code) ************* #!/bin/bash # Use the first argument as OUTPUT_DIRECTORY OUTPUT_DIRECTORY="$1" # Specify the file containing captured listener information listener_info_file="$OUTPUT_DIRECTORY/listener_info.log" # Specify the log file for relocation activities relocate_log_file="$OUTPUT_DIRECTORY/relocation_output.log"  # Change to desired name # Check if the listener info file exists if [ ! -f "$listener_info_file" ]; then     echo "Error: Missing listen

Scan listener capture

***Main script**** #!/bin/bash # Assign the provided OUTPUT_DIRECTORY to a variable OUTPUT_DIRECTORY="$1" # Function to log output log_output() {     local title="$1"     local command="$2"     # Determine the terminal width (columns)     columns=$(tput cols)     # Create a separator line with the determined width     separator_line=$(printf "%${columns}s\n" | tr '''-')     # Log section title with section number     echo "$separator_line" >> "$LOG_FILE"     echo "Section $section_counter: $title" >> "$LOG_FILE"     echo "$separator_line" >> "$LOG_FILE"     # Increment section counter     ((section_counter++))     # Execute command and log its output     eval "$command" >> "$LOG_FILE" 2>&1     # Append separator line after command output     echo "$separator_line" >> "$LOG_FILE" } # Function to r

pfile create

Main script #!/bin/bash # Set OUTPUT_DIRECTORY with a directory name containing a dot export OUTPUT_DIRECTORY="/path/to/your/directory/xx.xd" # Function to log output log_output() {     local title="$1"     local command="$2"     # Execute command and log its output     eval "$command" >> "$LOG_FILE" 2>&1 } # Function to run pfile_create.sh run_pfile_create() {     sh pfile_create.sh "$OUTPUT_DIRECTORY" } # Log output log_output "Created Pfile" "run_pfile_create" ************ pfile_create.sh #!/bin/bash # Set OUTPUT_DIRECTORY with a directory name containing a dot OUTPUT_DIRECTORY="$1" # Loop through all Oracle databases running on the host for SID in $(ps -ef | grep '[o]ra_smon' | awk '{print $NF}' | cut -d '_' -f3); do     echo "Creating Pfile for $SID"          # Function to create a pfile using SQL*Plus     create_pfile() {         local output_di

oracle scripts

***** #!/bin/bash #!/bin/bash # Set OUTPUT_DIRECTORY export OUTPUT_DIRECTORY="/path/to/your/output/directory" # Function to create a pfile using SQL*Plus create_pfile() {     local output_directory="$1"          # Extract Oracle SID     local ORACLE_SID=$(ps -ef | grep '[o]ra_smon' | awk '{print $NF}' | cut -d '_' -f3)     echo "Oracle SID: $ORACLE_SID"     # Source oraenv to set Oracle environment variables     source oraenv <<< "$ORACLE_SID"     echo "Environment variables set for Oracle SID: $ORACLE_SID"     # SQL script for pfile creation     sql_script="$output_directory/create_pfile.sql"     echo "SQL script path: $sql_script"     # Pfile creation logic     cat > "$sql_script" <<EOF     create pfile='$output_directory/init_$ORACLE_SID.ora' from spfile;     exit; EOF     echo "Generated SQL script content:"     cat "$sql_script"     

Longops

-- Set the linesize (page size) and pagesize SET LINESIZE 120; -- Adjust based on your desired line size SET PAGESIZE 50;  -- Adjust based on your desired page size -- Set column formatting COLUMN spid FORMAT 99999 COLUMN pid FORMAT 99999 COLUMN username FORMAT A15 COLUMN osuser FORMAT A15 COLUMN status FORMAT A10 COLUMN sid FORMAT 99999 COLUMN program FORMAT A30 -- Execute your query SELECT p.spid, p.pid, s.username, s.osuser, s.status, s.sid, s.program FROM v$process p JOIN v$session s ON s.paddr = p.addr WHERE s.status = 'ACTIVE'    AND s.program NOT LIKE 'oracle@%'  -- Exclude Oracle processes   AND s.program NOT LIKE 'J00%'     -- Adjust to exclude other background processes   AND s.program NOT LIKE '%BACKGROUND%' ORDER BY s.status;

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_tim

Filesystem usage

dcli -l oracle -g ~/dba_groups df -h | grep -E '([8-9][0-9]|100)%' | column  -t > filtered_log_file.txt

Database version list for patching

# Remove all existing log files rm -f db_version_*.txt # Loop through each database for SID in $(ps -ef | grep '[o]ra_smon' | awk '{print $NF}' | cut -d '_' -f3); do     export ORACLE_SID=$SID     source oraenv <<< "$SID"     # Execute SQL query to get the version     version=$(sqlplus -S / as sysdba <<EOF     set heading off     set feedback off     SELECT i.version FROM v\$instance i;     EXIT; EOF )     # Sanitize the version string for use in a file name     sanitized_version=$(echo "$version" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')     # Create a new log file for each database     output_file="db_version_${sanitized_version}.txt"     # Capture the database name using sqlplus command     database_name=$(sqlplus -S / as sysdba <<EOF     set heading off     set feedback off     SELECT d.name FROM v\$database d;     EXIT; EOF )     # Echo the database name to the log file, exc