Thursday, August 3, 2023

Invalid Objects script mew

#!/usr/bin/ksh


# Define variables

OUTPUT_FILE="invalids.html"

RECIPIENT="user@example.com"


# Write SQL query to script file

echo "SET MARKUP HTML ON

COLUMN OWNER FORMAT A9

COLUMN OBJECT_NAME FORMAT A31

COLUMN OBJECT_TYPE FORMAT A15

COLUMN LAST_DDL_TIME FORMAT A10

SPOOL $OUTPUT_FILE

SELECT OWNER, OBJECT_NAME, OBJECT_TYPE, LAST_DDL_TIME

FROM DBA_OBJECTS

WHERE STATUS='INVALID'

ORDER BY OWNER;

SET MARKUP HTML OFF" > pmopt.sql


# Run SQL query and spool output to file

sqlplus -s username/password@database @pmopt.sql >> /dev/null


# Replace special characters with HTML tags

sed -i 's/</\&lt;/g' $OUTPUT_FILE

sed -i 's/>/\&gt;/g' $OUTPUT_FILE


# Modify HTML output to include only the table

awk 'NR>14' $OUTPUT_FILE | sed 's/INVALID/<span style="color:red;font-weight:bold;">INVALID<\/span>/g' > temp_file && mv temp_file $OUTPUT_FILE


# Send email with HTML-formatted output in the body

mailx -a "Content-Type: text/html" -s "Invalid Objects Report" $RECIPIENT < $OUTPUT_FILE


No comments:

Post a Comment