Friday, March 3, 2023

adpatch

#!/bin/bash

# Set database connection details
db_user="APPS"
db_pass="yourpassword"
db_host="yourhostname"
db_port="1521"
db_sid="yoursid"

# Set email address
email="youremail@example.com"

# Query ad_applied_patches table
patches=$(sqlplus -s $db_user/$db_pass@$db_host:$db_port/$db_sid <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT patch_name || ' - ' || patch_type || ' - ' || creation_date FROM ad_applied_patches;
EXIT;
EOF)

# Format output as HTML table
output="<html><body><h1>List of applied patches:</h1><table><tr><th>Patch Name</th><th>Patch Type</th><th>Creation Date</th></tr>"
while read -r line; do
    IFS='-' read -ra arr <<< "$line"
    output+="<tr>"
    for i in "${arr[@]}"; do
        output+="<td>$i</td>"
    done
    output+="</tr>"
done <<< "$patches"
output+="</table></body></html>"

# Send email using mailx command with -S option instead of -a option
echo "$output" | mailx -S "Content-type: text/html;" -s "Patches Report" $email


No comments:

Post a Comment