Shell scripting unable to send the sql query data in table in body of email

I have written a shell script that calls below sql file. It is not sending the query data in table in the body of email.

spool table_update.html;
SELECT * FROM PROCESS_LOG_STATS where process = 'ActivateSubscription';
spool off;
exit;

Hello and Welcome to The UNIX and Linux Forums!

Your Post was moved to shell scripting forum

Please read the our FAQ on how to post new threads in the forums.

As a registered user you can go to any forum where you have permission to post and create new threads, view threads and leave replies. You should always search the forums before posting a new thread (Google Site Search).

To create a new thread, click on a forum you would like to post in, for example, UNIX for Dummies Questions & Answers, and then click on the new thread icon

To reply you have a few options. You can click on the 'Post Reply' button and add a new post to the end of the thread. Alternatively, you can leave a quick reply in a quick editor box listed below the posts in the thread.

If you have further questions on forum operations, do not send email or private messages (PMs) to us. You are required to post these questions here:

Post Here to Contact Site Administrators and Moderators

Enjoy, Learn and Teach!

The UNIX and Linux Forums

Welcome to the forum

To be able to give you an answer, we would need to know the OS and shell you are using, and see your script and the error messages if any, the little SQL code extract you gave is clueless to us

I am using korn shell on an AIX machine..
shell script as below:

. /ptma/ptma.profile;
echo $DB_PASS | sqlplus $DB_USER@$DB_SID @/ptma/ActivationCountCheck/ActivationCountCheck.sql;
mail -s "Activation Count of Last Day" someone@something.com < table_update.html
exit;

while the sql file has:

spool table_update.html;
SELECT appid, sum(resp) 
FROM PROCESS_LOG_STATS 
where process = 'ActivateSubscription' and ddate > sysdate-2 group by process, appid ORDER BY process, appid;
spool off;

The mail is triggrred but body of mail has data in text format but not in proper report/excel/html format.

Looks like you will have to send your report as an attachment if you want to keep the HTML format...

This is how I used to transfer fancy stuff and binaries: (Because I remember at the time I had issues when sending .doc or .xls files...)

cp myheader > /tmp/mailtmpfile
uuencode /path/datafile datafile >> /tmp/mailtmpfile
cat /tmp/mailtmpfile | sendmail -t 
rm /tmp/mailttmpfile 

Thank you moderator! I am on verge to get this info.. if I succeed, I will paste it here... :slight_smile: I think its doable but its not easy.. I googled a lot but could not find it anywhere..

What does this give as output?

uuencode -m table_update.html table_update.html|  mail -s "Activation Count of Last Day" someone@something.com 

You do not generate any html code with your select statment, the attachment will be text again.
Follow this link to Oracles documentation to find out how to generate html using sqlplus.

Quite right Cero... So the issue might not be the mail body... but what the OP wanted in the body haha

Another problem is that mail, which usually links to mailx, generates mails with a header with Content-Type: text/plain.
This can be overwritten using the -a option of mailx (given that's the mailclient the OP usues).