Create pfile v1

 #!/bin/bash


OUTPUT_DIRECTORY="$1"


CURRENT_TIMESTAMP=$(date +"%Y%m%d_%H%M%S")


NEW_FOLDER="$OUTPUT_DIRECTORY/$CURRENT_TIMESTAMP"

BACKUP_FOLDER="$OUTPUT_DIRECTORY/backup_$CURRENT_TIMESTAMP"


mkdir -p "$NEW_FOLDER"


create_pfile() {

    local output_directory="$1"

    local oracle_sid="$2"

    

    source oraenv <<< "$oracle_sid" > /dev/null


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

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

exit;

EOF

)

}


# Loop through Oracle SIDs and create pfiles

for SID in $(ps -ef | grep '[o]ra_smon' | awk '{print $NF}' | cut -d '_' -f3); do

    create_pfile "$NEW_FOLDER" "$SID"

done


# If backup folder exists, rename it with timestamp

if [ -d "$OUTPUT_DIRECTORY/backup" ]; then

    mv "$OUTPUT_DIRECTORY/backup" "$BACKUP_FOLDER"

fi


# Move the new folder to the backup location

mv "$NEW_FOLDER" "$BACKUP_FOLDER"


echo "Pfiles created successfully in $BACKUP_FOLDER."

Comments

Popular posts from this blog

Oratab Entries validate and add

deployment pre patch

Golden gate v1