Friday, 10 March 2023

shell script to send sql query output to html format to mail body

 #!/bin/bash

# oracle credentials

set oracle env variablbles

# Email details

TO= mail id

subject =" report"

#get tablespace details

sqlplus -S / as sysdba << EOF > /tmp/tablespace_details.html

SET MARKUP HTML ON

SET FEEBACKUP OFF

SET VERIFY OFF

SET UNDERLINE OFF

SET TRIMSPOOL ON

SET LINESIZE 200

SET LONG 50000


----SQL QUERY

EOF

#get email content

body=$(cat /tmp/tablespace_details.html)

#send email

export CONTENT_TYPE=text/html

echo -e "TO:$TO\nSubject: $SUBJECT\nContent-Type:$CONTENT_TYPE\n\n$body" | /usr/sbin/sendmail -t


#clearnup


rm /tmp/tablespace_details.html



No comments:

Post a Comment

Featured post

duplicate db from standy to other server

 Duplicate Testuat   $ export ORACLE_SID=Testuat3 $ sqlplus '/as sysdba' Testuat3 SQL> alter system set cluster_database=FALSE sc...