I need to run a SQL query using SHELL script in PUTTY and send the results in email body in table format with headers along with a message line on top. I have written this so far but I am not able to get results in table format.
#! /bin/ksh
sqlplus -s user/pass @sid > /dev/null << EOF
whenever sqlerror exit 4;
set newpage 0
set space 0
set feedback off
set head off
set echo off
set pagesize 0
set serverout on
set trimspool on
set linesize 3000
spool $CSVFILE
select * from table;
spool off;
exit 0;
EOF
mailx -s "Subject Line" [email protected] < $CSVFILE
exit 0
The SQL is running fine and data is being saved in CSVFILE. The result I want should be in table format sent to the email address in email body and also involve a message line above table, something like so: EMAIL EXAMPLE WITH ROUGH TABLE
There are no errors. But no headers in CSVFILE even after putting SET HEAD ON. I have also tried the 'mail -a (content type)' solution but '-a' gives error.