Executing SQL Query and sending a mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing SQL Query and sending a mail
# 1  
Old 05-10-2011
Executing SQL Query and sending a mail

Hi all,

My reqirenet goes like this.

Need to execute one select statement within the script and send a mail to the users with the number of records fecthed from the query.

Please help..

Thanks.
# 2  
Old 05-10-2011
Try this.

Code:
sqlplus -s user/password@dbname <<EOF
set feedback off trimspool on 
spool file_name.txt;
select * from table_name;
spool off;
exit;
EOF


(uuencode file_name.txt file_name.txt )| mailx -s "subject XXXXX" user@mail.com

# 3  
Old 05-10-2011
Thank you Sir. Its working. Smilie

---------- Post updated at 04:04 AM ---------- Previous update was at 02:57 AM ----------

Need one clarification.

How can we capture the count from the SQL into the mail body?

Please help.
# 4  
Old 05-10-2011
Quote:
Originally Posted by Achiever
Thank you Sir. Its working. Smilie

---------- Post updated at 04:04 AM ---------- Previous update was at 02:57 AM ----------

Need one clarification.

How can we capture the count from the SQL into the mail body?

Please help.
Code:
sqlplus -s user/password@dbname <<EOF
set feedback off trimspool on 
spool file_name.txt;
select * from table_name;
spool off;
exit;
EOF


echo "the file count is"  >file_cnt.txt
##this will fetch the number of lines in the file
wc -l  file_name.txt >>file_cnt.txt


(cat file_cnt.txt ; uuencode file_name.txt file_name.txt )| mailx -s "subject XXXXX" user@mail.com


Last edited by palanisvr; 05-10-2011 at 08:01 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Problems sending mail: Difference between Mail and Mailx?

Whats the difference between mail and mailx? I'm trying to troubleshoot a problem where I can send mail from server A with this `echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS` command but executing the same command from server B throws me this error (Both servers are RHEL) ... (1 Reply)
Discussion started by: RedSpyder
1 Replies

2. UNIX for Dummies Questions & Answers

Regarding executing sql query in shell script

Hi, I have one SQL file prepared in UNIX and one script that is executing that. In SQL i have Update and create queries. I want to introduce conditions in SQL file (in UNIX) that if either of the create or update query failes whole transaction should be rollback. I just have 1 create... (2 Replies)
Discussion started by: abhii
2 Replies

3. Shell Programming and Scripting

Stop sending mail after certain number of mail

Hi guys... I am busy writing a script to notify me via an mail if my application is down. I have done that. Now I want this script to stop sending mails after five mails were sent but the script should keep on checking the application. When the application is up again that count should be... (5 Replies)
Discussion started by: Phuti
5 Replies

4. Shell Programming and Scripting

Importing data from PL/SQL then sending it through mail,HELP ME!

Is anyone here know how to make a script in UNIX which will do importing data from PL/SQL then sending it through mail? Can you give me sample script with explanation so it's easy to understand,Thank you very much,any suggestion or advice is welcome, (1 Reply)
Discussion started by: Atrap
1 Replies

5. UNIX for Dummies Questions & Answers

executing SQL query using unix shell script

I want to perform few post-session success tasks like update a status to 'true' in one of the sql database table, update date values to current system date in one of the configuration table in sql. How do i achieve this in a post session command?syntax with example will be helpful. (3 Replies)
Discussion started by: nathanvaithi
3 Replies

6. UNIX for Advanced & Expert Users

Issues while sending a mail having records fetched from SQL -all in UNIX

hi-I want to write a UNIX Script which will fetch records from Oracle database.I want to store these records in a file under fields like email address,name and the transaction_id and then fetch these records from the file and send the email to individual users with their transaction ID details. (4 Replies)
Discussion started by: DeepSalwan
4 Replies

7. Shell Programming and Scripting

Script executing sql query

Hello, I have a sh script excuting a sql query through sqlplus. I am having trouble making my date equal to the date of the server time in the sql script. How can i call the server date from my query? Thanks (2 Replies)
Discussion started by: kingluke
2 Replies

8. Shell Programming and Scripting

executing a SQL query in shell script

Hi ALL, I need an help in connecting to oracle database, executing a select query and printing it on the screen. Can any one please write a simple code or psuedo code and let me know. select query returns multiple values( say select name from emp) Thanks in advance LM (1 Reply)
Discussion started by: lijju.mathew
1 Replies

9. Shell Programming and Scripting

Executing Sql Query Using Shell Script

HI ALL i have a requirement like this. i have to write a shell script to run a sql query. DB is oracle. once the query is run, the results of the query has to be published in a data file. can you please advice me how to go about it. i am absolutely new to shell scripts and this is a part of my job. (14 Replies)
Discussion started by: ragha81
14 Replies

10. UNIX for Dummies Questions & Answers

Executing a SQL query from a shell script

I cannot figure out how to run a SQL script, or just a sqlplus query, from a shell script (bash or ksh). Basically, I need to su - oracle from root and run a query, then test the exit status. (3 Replies)
Discussion started by: 98_1LE
3 Replies
Login or Register to Ask a Question