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 tablespace_name, encrypted FROM dba_tablespaces;"
"SELECT * FROM dba_encrypted_columns;"
"SELECT os_username, username, MAX(timestamp), COUNT(*) FROM DBA_AUDIT_TRAIL WHERE action_name = 'LOGON' AND timestamp > sysdate-31 GROUP BY os_username, username;"
"SELECT db_unique_name, open_mode FROM v\$database;"
"SELECT DISTINCT SUBSTR(module, 5, 8) AS process FROM gv\$session WHERE username = 'GGUSER' AND module NOT LIKE 'ZenGate%' ORDER BY process;"
"SELECT capture_name FROM dba_capture;"
"SELECT module, action FROM gv\$session WHERE action LIKE 'OGG\$%';"
)
# Execute each query
for query in "${queries[@]}"; do
run_sql "$query"
done
# Database size check
echo "Database Size Check" >> $report_file
echo "----------------------------------------" >> $report_file
run_sql "SELECT
(SELECT SUM(bytes)/1024/1024/1024 FROM dba_data_files) AS \"Total Size (GB)\",
(SELECT SUM(bytes)/1024/1024/1024 FROM dba_segments) AS \"Used Space (GB)\",
(SELECT SUM(bytes)/1024/1024/1024 FROM dba_data_files) - (SELECT SUM(bytes)/1024/1024/1024 FROM dba_segments) AS \"Free Space (GB)\"
FROM dual;"
# SRVCTL status check
echo "SRVCTL Status Check" >> $report_file
echo "----------------------------------------" >> $report_file
srvctl status database -d $ORACLE_SID >> $report_file
echo "Pre-check report generated successfully at $report_file"
Comments
Post a Comment