Posts

Showing posts from June, 2024

SQL loader v1

 #!/bin/bash # Variables CSV_FILE="/path/to/your/file.csv" USERNAME="your_username" PASSWORD="your_password" DATABASE="your_database" TABLE="your_table" # SQL Loader Control File CONTROL_FILE="control_file.ctl" # Create control file cat <<EOF > $CONTROL_FILE LOAD DATA INFILE '$CSV_FILE' INTO TABLE $TABLE FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (   column1,   column2,   column3   -- add all your columns here ) EOF # Run SQL*Loader sqlldr $USERNAME/$PASSWORD@$DATABASE CONTROL=$CONTROL_FILE LOG=loader.log BAD=loader.bad # Check if sqlldr command was successful if [ $? -eq 0 ]; then   echo "Data loaded successfully into $TABLE." else   echo "Failed to load data into $TABLE." fi

Decommission

 #!/bin/bash # Set environment variables using oraenv export ORAENV_ASK=NO export ORACLE_SID=$1 . oraenv # Helper function to execute SQL commands run_sql() {   sqlplus -s "/ as sysdba" <<EOF   $1 EOF } # Helper function to execute DGMGRL commands and capture output run_dgmgrl() {   dgmgrl -silent <<EOF   connect /   $1 EOF } # Run DGMGRL show configuration and capture output run_dgmgrl "show configuration;" > dr_info.txt # Check if Data Guard is available if grep -qE "ORA-16525|ORA-16596" dr_info.txt; then   echo "Data Guard not available for $ORACLE_SID" >> dr_info.txt   exit 1 fi # Get the primary and standby database names PRIMARY_DB=$(grep -E "Primary database" dr_info.txt | awk '{print $3}') STANDBY_DB=$(grep -E "Standby database" dr_info.txt | awk '{print $3}') # Ensure that we found the primary and standby databases if [ -z "$PRIMARY_DB" ] || [ -z "$STANDBY_DB" ]...

Pre check database

 #!/bin/bash export ORAENV_ASK=NO export ORACLE_SID=$1 export frame=$2 db_name=${ORACLE_SID%?} . oraenv report_file="pre_check_report_$(date +%F).log" sqlplus -s / as sysdba <<EOF >> $report_file @queries.sql exit; EOF autosys.ksh -h $frame -d $db_name -c delete dgmgrl / <<EOF >> $report_file show configuration; EOF if grep -qE "ORA-16525|ORA-16596" "$report_file"; then     echo "Data Guard not available for $db_name" >> $report_file fi DB_NAME=$(grep -E "Standby Physical" $report_file | awk '{print $1}') dgmgrl / <<EOF >> $report_file show database "$DB_NAME"; EOF export ASM_SID=$(ps -ef | grep [a]sm_smon.*+ASM | awk '{print $NF}' | cut -d'+' -f3) . oraenv <<< "$ASM_SID" srvctl status database -d $db_name -v agctl status goldengate > goldengate_status_log.log running_instances_with_manager=$(grep "is running" goldengate_status_lo...

Dba

 #!/bin/bash # Set environment variables using oraenv export ORAENV_ASK=NO export ORACLE_SID=$1 . oraenv # Define output report file report_file="pre_check_report_$(date +%F).txt" # Create a new report file and add header echo "Pre-check Report for Database: $ORACLE_SID" > $report_file echo "Generated on: $(date)" >> $report_file echo "----------------------------------------" >> $report_file # Function to run a SQL command and append output to the report run_sql() {   sqlplus -s "/ as sysdba" <<EOF >> $report_file SET PAGESIZE 100 LINESIZE 255 $1 EOF   echo "----------------------------------------" >> $report_file } # List of SQL queries to execute queries=(   "SELECT name FROM v\$database;"   "SELECT sysdate FROM dual;"   "SELECT service_name, COUNT(*) FROM gv\$session GROUP BY service_name;"   "SELECT * FROM v\$encryption_wallet;"   "SELECT table...

Task

 #!/bin/bash # Set environment variables using oraenv export ORAENV_ASK=NO export ORACLE_SID=$1 . oraenv # Define output report file report_file="pre_check_report_$(date +%F).txt" # Create a new report file and add header echo "Pre-check Report for Database: $ORACLE_SID" > $report_file echo "Generated on: $(date)" >> $report_file echo "----------------------------------------" >> $report_file # Function to run a SQL command and append output to the report run_sql() {   sqlplus -s "/ as sysdba" <<EOF >> $report_file SET PAGESIZE 100 LINESIZE 255 $1 EOF   echo "----------------------------------------" >> $report_file } # List of SQL queries to execute queries=(   "SELECT name FROM v\$database;"   "SELECT sysdate FROM dual;"   "SELECT service_name, COUNT(*) FROM gv\$session GROUP BY service_name;"   "SELECT * FROM v\$encryption_wallet;"   "SELECT table...