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...

thanks
LVL 5
CalmSoulAsked:
Who is Participating?
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.

MikeOM_DBACommented:
You can do something like this:
ORACLE_SID=orcl
ORAENV_ASK=NO
. /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
spo $REPORT
SELECT * FROM EMP;
exit
EOSQL

uuencode $REPORT <$REPORT|mailx -s"$REPORT" mike@mycompany.com lizzie@mycompany.com Elka@mycompany.com

Open in new window

0

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?
0
MikeOM_DBACommented:
What connection string?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

CalmSoulAuthor Commented:
I mean what does in oracle_home parameter?
0
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.
0
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.
0
CalmSoulAuthor Commented:
Hello Slightwv:

Do you have simple example of UTL_SMTP procedures?

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

http://www.experts-exchange.com/Database/Oracle/Q_26826313.html
http://www.experts-exchange.com/Database/Oracle/Q_23829263.html#a22757547

There are also any examples on the web.

If your email server requires authentication, an Expert here has written articles on it:
http://www.experts-exchange.com/articles/5915/How-to-Authenticate-to-an-SMTP-server-with-Oracle-PL-SQL.html


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.
0
MikeOM_DBACommented:

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

Open in new window

0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.