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_directory="$1"

        local oracle_sid="$2"


        echo "Output Directory: $output_directory"

        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"


        # Directly use here document in sqlplus command

        result=$(sqlplus -S / as sysdba <<EOF

        create pfile='$output_directory/init_$oracle_sid.ora' from spfile;

        exit;

EOF

)

        # Check if the pfile was created successfully

        pfile_path="$output_directory/init_$oracle_sid.ora"

        

        if [ -f "$pfile_path" ]; then

            echo "Pfile created successfully for $oracle_sid."

        else

            echo "Error: Pfile creation failed for $oracle_sid. Details: $result"

        fi

    }


    # Call the function to create pfile for the current SID

    create_pfile "$OUTPUT_DIRECTORY" "$SID"

done

Comments

Popular posts from this blog

SQL Loader V3

Db Unix

Standby redo log add