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"
# Execute SQL script using SQL*Plus
sqlplus / as sysdba @"$sql_script" >> "$LOG_FILE" 2>&1
# Remove the temporary SQL script file
rm -f "$sql_script"
}
# Example usage
create_pfile "$OUTPUT_DIRECTORY"
*******
# 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)
# Source oraenv to set Oracle environment variables
source oraenv <<< "$ORACLE_SID"
# SQL script for pfile creation
sql_script="$output_directory/create_pfile.sql"
# Pfile creation logic
cat > "$sql_script" <<EOF
create pfile='$output_directory/init_$ORACLE_SID.ora' from spfile;
exit;
EOF
# Execute SQL script using SQL*Plus
sqlplus / as sysdba @"$sql_script" >> "$LOG_FILE" 2>&1
# Remove the temporary SQL script file
rm -f "$sql_script"
}
# Example usage
create_pfile "$OUTPUT_DIRECTORY"
*******
# Prompt the user for the SCRIPTS DIRECTORY input
read -p "Enter SCRIPTS DIRECTORY: " SCRIPTS_DIRECTORY
# Prompt the user for the OUTPUT DIRECTORY input
read -p "Enter OUTPUT DIRECTORY: " OUTPUT_DIRECTORY
# Create the LOG_FILE variable using OUTPUT_DIRECTORY
LOG_FILE="$OUTPUT_DIRECTORY/consolidated.log"
# Export ORACLE_SID
export ORACLE_SID=$(ps -ef | grep '[a]sm_smon.*+ASM' | awk '{print $NF}' | cut -d '_' -f3)
# Source oraenv
source oraenv <<< "$ORACLE_SID"
# Specify the file to store listener information
listener_info_file="$OUTPUT_DIRECTORY/pre_patch_listener_info.log"
# Specify the log file for capturing listener information
capture_log_file="$OUTPUT_DIRECTORY/pre_patch_capture_log.log"
# Capture listener names and current nodes, logging activity
srvctl status scan_listener -all | awk '/LISTENER_SCAN[0-9]+/ {listener=$3; getline; print listener, $NF}' > "$listener_info_file" 2>&1
# Display Listener Information
cat "$listener_info_file"
**************
#!/bin/bash
# Ask user for scripts directory
read -p "Enter the desired scripts directory: " SCRIPTS_DIRECTORY
# Normalize directory path (remove trailing slashes)
SCRIPTS_DIRECTORY="${SCRIPTS_DIRECTORY%/}"
# Validate directory existence and permissions
if [[ ! -d "$SCRIPTS_DIRECTORY" ]]; then
echo "Error: Scripts directory '$SCRIPTS_DIRECTORY' does not exist."
exit 1
fi
if [[ ! -r "$SCRIPTS_DIRECTORY" ]]; then
echo "Error: Insufficient read permissions for scripts directory '$SCRIPTS_DIRECTORY'."
exit 1
fi
# Ask user for output directory
read -p "Enter the desired output directory: " OUTPUT_DIRECTORY
# Normalize directory path (remove trailing slashes)
OUTPUT_DIRECTORY="${OUTPUT_DIRECTORY%/}"
# Create output directory if needed
if [[ ! -d "$OUTPUT_DIRECTORY" ]]; then
echo "Creating output directory: $OUTPUT_DIRECTORY"
mkdir -p "$OUTPUT_DIRECTORY" || {
echo "Error: Failed to create output directory '$OUTPUT_DIRECTORY'."
exit 1
}
fi
# Set the log file path
LOG_FILE="$OUTPUT_DIRECTORY/consolidated.log"
# Redirect output and error to the log file
exec >> "$LOG_FILE" 2>&1
# Check if script exists
if [[ ! -f "$SCRIPTS_DIRECTORY/$SCRIPT_NAME" ]]; then
echo "Error: Script '$SCRIPT_NAME' not found in '$SCRIPTS_DIRECTORY'."
exit 1
fi
# Ensure script has execute permission
if [[ ! -x "$SCRIPTS_DIRECTORY/$SCRIPT_NAME" ]]; then
echo "Error: Script '$SCRIPT_NAME' does not have execute permission."
exit 1
fi
# Log execution start
echo "Starting script '$SCRIPT_NAME' at $(date)"
# Run the script
sh "$SCRIPTS_DIRECTORY/$SCRIPT_NAME" || {
echo "Error: Script '$SCRIPT_NAME' failed."
exit 1
}
# Log execution end
echo "Script '$SCRIPT_NAME' completed at $(date)"
echo "Output and logs saved to: $OUTPUT_DIRECTORY/$LOG_FILE"
********
#!/bin/bash
# Ask user for scripts directory
read -p "Enter the desired scripts directory: " SCRIPTS_DIRECTORY
# Normalize directory path (remove trailing slashes)
SCRIPTS_DIRECTORY="${SCRIPTS_DIRECTORY%/}"
# Validate directory existence and permissions
if [[ ! -d "$SCRIPTS_DIRECTORY" ]]; then
echo "Error: Scripts directory '$SCRIPTS_DIRECTORY' does not exist."
exit 1
fi
if [[ ! -r "$SCRIPTS_DIRECTORY" ]]; then
echo "Error: Insufficient read permissions for scripts directory '$SCRIPTS_DIRECTORY'."
exit 1
fi
# Ask user for output directory
read -p "Enter the desired output directory: " OUTPUT_DIRECTORY
# Normalize directory path (remove trailing slashes)
OUTPUT_DIRECTORY="${OUTPUT_DIRECTORY%/}"
# Validate directory existence and permissions
if [[ ! -d "$OUTPUT_DIRECTORY" ]]; then
echo "Error: Output directory '$OUTPUT_DIRECTORY' does not exist."
exit 1
fi
if [[ ! -w "$OUTPUT_DIRECTORY" ]]; then
echo "Error: Insufficient write permissions for output directory '$OUTPUT_DIRECTORY'."
exit 1
fi
# Create output directory if needed
if [[ ! -d "$OUTPUT_DIRECTORY" ]]; then
mkdir "$OUTPUT_DIRECTORY"
fi
# Set the log file path
LOG_FILE="$OUTPUT_DIRECTORY/consolidated.log"
# Redirect output and error to the log file
exec >> "$LOG_FILE" 2>&1
# ... your script logic here ...
# Example usage within your script (replace with your actual commands):
echo "Running script from: $SCRI
PTS_DIRECTORY"
sh "$SCRIPTS_DIRECTORY/GG_pumps.sh"
********************
# Prompt the user for the SCRIPTS DIRECTORY input
read -p "Enter SCRIPTS DIRECTORY: " SCRIPTS_DIRECTORY
# Prompt the user for the OUTPUT_DIRECTORY input
read -p "Enter OUTPUT DIRECTORY: " OUTPUT_DIRECTORY
# Create the LOG_FILE variable using OUTPUT_DIRECTORY
LOG_FILE="$OUTPUT_DIRECTORY/consolidated.log"
# Use the variables in your script as needed
echo "SCRIPTS DIRECTORY: $SCRIPTS_DIRECTORY"
echo "OUTPUT DIRECTORY: $OUTPUT_DIRECTORY"
echo "LOG FILE: $LOG_FILE"
*******
#!/bin/bash
# Set default directories (optional, adjust as needed)
DEFAULT_SCRIPTS_DIR="/xx/yy/tt/"
DEFAULT_OUTPUT_DIR="/xu/yh/tk/"
# Prompt user for confirmation or changes to directories
read -p "Use default scripts directory ($DEFAULT_SCRIPTS_DIR)? (y/N): " use_default_scripts
read -p "Use default output directory ($DEFAULT_OUTPUT_DIR)? (y/N): " use_default_output
# Get user input if applicable
if [[ "$use_default_scripts" != "y" ]]; then
read -p "Enter desired scripts directory: " SCRIPTS_DIRECTORY
fi
if [[ "$use_default_output" != "y" ]]; then
read -p "Enter desired output directory: " OUTPUT_DIRECTORY
fi
# Normalize directory paths (remove trailing slashes)
SCRIPTS_DIRECTORY="${SCRIPTS_DIRECTORY%/}"
OUTPUT_DIRECTORY="${OUTPUT_DIRECTORY%/}"
# Validate directory existence and permissions
if [[ ! -d "$SCRIPTS_DIRECTORY" ]]; then
echo "Error: Scripts directory '$SCRIPTS_DIRECTORY' does not exist."
exit 1
fi
if [[ ! -d "$OUTPUT_DIRECTORY" ]]; then
echo "Error: Output directory '$OUTPUT_DIRECTORY' does not exist."
exit 1
fi
if [[ ! -w "$OUTPUT_DIRECTORY" ]]; then
echo "Error: Insufficient write permissions for output directory '$OUTPUT_DIRECTORY'."
exit 1
fi
# Create output directory if needed
if [[ ! -d "$OUTPUT_DIRECTORY" ]]; then
mkdir "$OUTPUT_DIRECTORY"
fi
# Set log file path
LOG_FILE="$OUTPUT_DIRECTORY/consolidated.log"
# Redirect output and error to the log file
exec >> "$LOG_FILE" 2>&1
# ... your script logic here ...
# Example usage within your script (replace with your actual commands):
echo "Running script from: $S
CRIPTS_DIRECTORY"
sh "$SCRIPTS_DIRECTORY/GG_pumps.sh"
********
# source env
source env
# export ORACLE_SID
export ORACLE_SID=$(ps -ef | grep '[a]sm_smon.*+ASM' | awk '{print $NF}' | cut -d '_' -f3)
# source oraenv
source oraenv <<< "$ORACLE_SID"
# Specify the file to store listener information
listener_info_file="$OUTPUT_DIRECTORY/pre_patch_listener_info.log"
# Specify the log file for capturing listener information
capture_log_file="$OUTPUT_DIRECTORY/pre_patch_capture_log.log"
# Capture listener names and current nodes, logging activity
srvctl status scan_listener -all | awk '/LISTENER_SCAN[0-9]+/ {listener=$3; getline; print listener, $NF}' > "$listener_info_file"
# Display Listener Information
cat "$listener_info_file"
*********
#!/bin/bash
# ...
# Initialize section counter
section_counter=1
# Function to log section titles and command output to the consolidated log file
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"
}
***************
#!/bin/bash
# ...
# Function to log section titles and command output to the consolidated log file
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
echo "$separator_line" >> "$LOG_FILE"
echo "$title" >> "$LOG_FILE"
echo "$separator_line" >> "$LOG_FILE"
# Execute command and log its output
eval "$command" >> "$LOG_FILE" 2>&1
# Append separator line after command output
echo "$separator_line" >> "$LOG_FILE"
}
******#!/bin/bash
# ...
# Function to log commands and their output to the consolidated log file
log_command() {
local command="$1"
local log_command=true # Set to false to skip logging the command
if [ "$#" -eq 2 ] && [ "$2" == "skip_command_log" ]; then
log_command=false
fi
if [ "$log_command" == true ]; then
echo "Running: $command" >> "$LOG_FILE"
fi
eval "$command" >> "$LOG_FILE" 2>&1
echo "--------------------------------------" >> "$LOG_FILE"
}
#!/bin/bash
NFS_LOCATION="/xxx/yyy/zzz"
CHANGE_NUMBER="CHG0000000"
FRAME="xyzxyz"
SCRIPTS_DIRECTORY="$NFS_LOCATION/$CHANGE_NUMBER/$FRAME/scripts"
OUTPUT_DIRECTORY="$NFS_LOCATION/$CHANGE_NUMBER/$FRAME"
LOG_FILE="$OUTPUT_DIRECTORY/consolidated_log.txt"
# Function to log commands and their output to the consolidated log file
log_command() {
echo "Running: $1" >> "$LOG_FILE"
eval "$1" >> "$LOG_FILE" 2>&1
echo "--------------------------------------" >> "$LOG_FILE"
}
# Ensure directories are created
mkdir -p "$SCRIPTS_DIRECTORY"
mkdir -p "$OUTPUT_DIRECTORY"
# Log directory creation
log_command "mkdir -p \"$SCRIPTS_DIRECTORY\""
log_command "mkdir -p \"$OUTPUT_DIRECTORY\""
# Log script directory
log_command "echo \$SCRIPT_DIR"
# OEM Blackout Create (Cluster Level Blackout)
log_command "sh oem_blackout.sh"
# OLSNODES
log_command "olsnodes -done merger with this"
log_command "echo cluster_nodes={\$(olsnodes | tr '\\n' ','| sed 's/,$//')}"
# Database Details
log_command "srvctl config database"
log_command "srvctl config database -v"
# Cluster Details
log_command "crsctl stat res -t -w \"TYPE = ora.database.type\" | awk '{printf \"%-20s %-20s %-20s %-20s %-500s %-20s\\n\",\$1, \$2, \$3, \$4, \$5 ,\$6}'"
# Goldengate Details
log_command "export ORACLE_SID=\$(ps -ef | grep '[a]sm_smon.*+ASM' | awk '{print \$NF}' | cut -d '_' -f3)"
log_command "source oraenv <<< \"\$ORACLE_SID\""
log_command "agctl status goldengate"
log_command "for value in \$(locate setup_ogg); do source \$value; cd \$GG_HOME; echo \"info all\" | ./ggsci; done"
log_command "sh \$SCRIPTS_DIRECTORY/GG_pumps.sh"
# ACFS Details
log_command "for value in \$(df -kh | grep gg | awk '{print \$NF}'); do acfsutil repl info -c \"\$value\"; done"
# Filesystem Details
log_command "dcli -l oracle -g /home/oracle/dbs_group df -kh"
# Scan Listener Details
log_command "scan listener - done merger with this"
# Pre-Check Script Execute
log_command "cd $SCRIPTS_DIRECTORY"
log_command "cp pre_homes_manual.cfg ../"
log_command "dcli -l oracle -g ~/dbs_group --serial $SCRIPTS_DIRECTORY/pre.ksh -e y -d $SCRIPTS_DIRECTORY > pre.out"
# ... (Insert the rest of your script, using log_command for each command)
# Example:
# log_command "sh $SCRIPTS_DIRECTORY/cluster_health_final.sh"
# Create Pfile
log_command "for SID in \$(ps -ef | grep '[o]ra_smon' | awk '{print \$NF}' | cut -d '_' -f3); do export ORACLE_SID=\$SID; source oraenv <<< \"\$SID\"; sqlplus / as sysdba <<EOF; create pfile='\$OUTPUT_DIRECTORY/init_\${SID}.ora' from spfile; EXIT; EOF; done"
# /u01 Filesystem Space Check
log_command "dcli -g ~/dbs_group -l oracle df -h /u01 | column -t"
# Create Restore Point For All Database
log_command "mkdir -p $OUTPUT_DIRECTORY/RP_LOGS"
log_command "dcli -l oracle -g /home/oracle/dbs_group --serial $SCRIPTS_DIRECTORY/create_rp.ksh -d $OUTPUT_DIRECTORY/RP_LOGS -r RP_BEFORE_APR2023_PSU"
# ... (Insert the remaining script)
# End of script
echo "Consolidated script completed. Log available at: $LOG_FILE"
Comments
Post a Comment