Shell Script for Daily to Identify New Invalid generated daily in Oracle Database
In this post, I am sharing a shell script to daily identify if there are any new invalids generated in oracle database.
You can modify and change as you want.
Scripts:
vi invalids.sh
#!/bin/bash# Set environment variables (adjust as needed based on env)export ORACLE_SID=FOA12export PATH=$ORACLE_HOME/bin:$PATHexport ORAENV_ASK=NO#Mail functionalityRECIPIENTS=support@funoracleapps.comsend_mail() {mailx -s "New Invalid Objects Detected" ${RECIPIENTS} < mail_body.txt}# Directory to store previous invalids listPREVIOUS_INVALIDS_FILE="/tmp/previous_invalids.txt"# Directory to store current invalids listCURRENT_INVALIDS_FILE="/tmp/current_invalids.txt"# Get current invalid objectssqlplus -S "/as sysdba" <<EOFSET PAGESIZE 0SET FEEDBACK OFFSET VERIFY OFFSET HEADING OFFSPOOL $CURRENT_INVALIDS_FILESELECT object_name FROM dba_objects WHERE status = 'INVALID';SPOOL OFFEXITEOF# Check if the previous invalids file existsif [[ -f $PREVIOUS_INVALIDS_FILE ]]; then# Compare current and previous invalids to find new invalidscomm -13 <(sort $PREVIOUS_INVALIDS_FILE) <(sort $CURRENT_INVALIDS_FILE) > new_invalids.txtif [[ -s new_invalids.txt ]]; then# Send email notification with new invalidsecho "New invalid objects found:" > mail_body.txtcat new_invalids.txt >> mail_body.txtsend_mailelseecho "No new invalid objects found."fielseecho "Script is running first time or previous invalid object data file is not present"sort $CURRENT_INVALIDS_FILE > new_invalids.txtcat new_invalids.txt >> mail_body.txtsend_mailfi# Replace previous invalids file with current onecp $CURRENT_INVALIDS_FILE $PREVIOUS_INVALIDS_FILE# Clean up temporary filesrm -f new_invalids.txt mail_body.txt
Post a Comment
Post a Comment