email the results from oracle query shell script

Hello Experts:

I am looking for a shell script which will email oracle query results to multiple email addresses. It will be cronjob which will run daily...

Oracle query is just simple select statement...

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can do something like this:
. /usr/local/bin/oraenv $ORACLE_SID
REPORT=/path/to/my/report/RESULT_`date +%Y\-%m\-%d`.txt
sqlplus -s /nolog <<EOSQL 
conn scott/tiger
set pages 49999 lin 120 trims on echo off term off

uuencode $REPORT <$REPORT|mailx -s"$REPORT"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CalmSoulAuthor Commented:
How I will setup connection string with ora?
What connection string?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

CalmSoulAuthor Commented:
I mean what does in oracle_home parameter?
slightwv (䄆 Netminder) Commented:
>>How I will setup connection string with ora?

That is in the script posted:  conn scott/tiger

If you just want the results of a select emailed to people, why not let the database do it internally?

There are several samples on this site that use UTL_SMTP procedures to generate and send emails directly from the database.

My databases email me every morning.  Nothing in the OS to worry about.
slightwv (䄆 Netminder) Commented:
>>I mean what does in oracle_home parameter?

ORACLE_HOME can be set using the oraenv script provided by Oracle.

The example is also in the script provided:  . /usr/local/bin/oraenv $ORACLE_SID

Change ORCL to the correct SID, change the PATH to oraenv to match you setup.
CalmSoulAuthor Commented:
Hello Slightwv:

Do you have simple example of UTL_SMTP procedures?

slightwv (䄆 Netminder) Commented:
Did you try searching the site?

There are also any examples on the web.

If your email server requires authentication, an Expert here has written articles on it:

You might find references to UTL_MAIL which is a package provided by Oracle.  I'm not sure if it can send an email to multiple users.

How I will setup connection string with ora?
ORACLE_SID=orcl   #<= Replace with your sid
. /usr/local/bin/oraenv $ORACLE_SID

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.