#!/bin/bash
# Source the environment . /path/to/env_file # Prompt for user input read -p "Enter the patch number: " patch_number # Execute SQL query and save output to a CSV file sqlplus -S /nolog <<EOF connect username/password@database set heading off set feedback off set pagesize 0 set linesize 1000 set colsep ',' spool output.csv SELECT driver.driver_file_name, TO_CHAR(run.start_date, 'DD-Mon HH24:MI:SS') AS start_date, TO_CHAR(run.end_date, 'DD-Mon HH24:MI:SS') AS end_date, lang.language FROM ad_patch_runs run, ad_patch_driver_langs lang, ad_patch_drivers driver, ad_applied_patches applied WHERE run.patch_driver_id = driver.patch_driver_id AND driver.applied_patch_id = applied.applied_patch_id AND applied.patch_name = '$patch_number' AND lang.patch_driver_id = driver.patch_driver_id ORDER BY 1, 2, 3; spool off exit; EOF # Convert CSV to Excel format ssconvert output.csv output.xlsx # Send email with the Excel file as an attachment echo "Please find the attached Excel file." | mailx -s "Patch Report" -a output.xlsx user@example.com
No comments:
Post a Comment