Run sql script and send to mail if not empty?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run sql script and send to mail if not empty?
# 1  
Old 08-12-2013
Hammer & Screwdriver Run sql script and send to mail if not empty?

Thanks again for helping me out.

I was wondering if anyone else has encountered this issue.

I have a SQL script that produces a list -however we are only interested in that list if the length is not zero

Here is the sql file named dailyBalance.sql

Code:
select * from Balance where TotalBalance <0;

Here is the shell script that calls it:

Code:
#!/bin/sh

rm -f /home/astrocloud/cron_scripts/dailyBalanceChk/dailyBalance.csv
mysql -uastrocloud -pThisIsMyPassword astrocloud_daily -B < /home/astrocloud/cron_scripts/dailyBalanceChk/dailyBalance.sql|sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g'> /home/astrocloud/cron_scripts/dailyBalanceChk/dailyBalance.csv

Of course I have my own fubar way of going about it -writing a sql count of the list into a file then reading the file and if the file says 0 then don't email else email that csv list.

I hope I've given enough information.
Any suggestions?
# 2  
Old 08-12-2013
You could test for file existence and size > zero (man sh): test -s /home/astrocloud/cron_scripts/dailyBalanceChk/dailyBalance.csv
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Run a sql script on multiple $Oracle_SID at once and send an alert if reaches the threshold

I am trying to accomplish following tasks in my KSH script: Run a sql script on multiple $ORACLE_SID at once Sends an alert only if the threshold > 2 for any of the $ORACLE_SID Please advice as to how I can approach this!! Thanks in advance! (1 Reply)
Discussion started by: jd_2000
1 Replies

4. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

5. Shell Programming and Scripting

script to send mail !!

Hi Experts.. i have created a table with the fields, empid name mailid 1 raja raja@xy.com and entered the values of all persons who are in that file... i have a .csv file date shift1 shift2 6/6/2011 ram raja Now i want a script that could fetch the data in (input file .csv file) and... (3 Replies)
Discussion started by: cratercrabs
3 Replies

6. Shell Programming and Scripting

how to run a script using cron job and send the output as attachment via e-mail using unix

how to run a script using cron job and send the output as attachment via e-mail using unix. please help me. how my cron job entry should be? As of now my cron job entry is to run the script at specific time, 15 03 * * * /path/sample.sh | mail -s "Logs" email_id In the above entry, what... (8 Replies)
Discussion started by: vidhyaS
8 Replies

7. Shell Programming and Scripting

Help-send mail script

Hi, I have written one script for sending mails with attachment. currently its working for only one recipient. I want to send mails to n number of users by taking user input i.e number of users. Output of current script: Enter how many files : 1 Enter First Name : kiran E-Mail... (2 Replies)
Discussion started by: kiran_j
2 Replies

8. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

9. Shell Programming and Scripting

Calling SQL script from ksh job and send mail on some error.

Hi, I am trying to call sql script from ksh job with parameters.The parameters passed from ksh job will be used in SELECT query in sql file to SPOOL the data in extract file.My questions are: 1) How to call a sql script from ksh job with parameters? 2) How to use the parameter in sql file to... (1 Reply)
Discussion started by: anil029
1 Replies

10. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies
Login or Register to Ask a Question