Need help on conditional emailing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help on conditional emailing
# 1  
Old 05-25-2015
Need help on conditional emailing

Hi All,

The following databse table maintains
VENDOR and EMAIL details.

Code:
VENOR_NAME VENDOR_EMAIL

DELL        surendra@dell.com
HP          rajkamal@hp.com
ACER        sumathi@acer.com
NOKIA       kunal@nokia.com
SONY        sinu@sony.com

We have to find emaild id of a vendor based on the vendor name
since email id can be change at any point of time.

The following files has to be emailed to corresponding vendor.

Code:
stock_dell_file
stock_hp_file
stock_acer_file
stock_nokia_file
stock_sony_file


If file is stock_dell_file then mail has to go to surendra@dell.com,
If file is stock_hp_file then mail has to go to rajkamal@hp.com,
If file is stock_acer_file then mail has to go to sumathi@acer.com, and so on.

Please help me on KSH.

Thanks.
# 2  
Old 05-25-2015
What have you got/tried so far?
# 3  
Old 05-26-2015
Hi,

So far I tried this to get email IDs from DATABASE
this is also not working.

Code:
#!/bin/ksh
RET_VALUE = 'sqlplus $ORACLE_CONNECTION << EOF
set serveroutput on
  declare 
 V_NAME varchar2(100);
 V_NAME1 varchar2(100);
 V_name2 VARCHAr2(100);
    ven_rec VENDOR%rowtype;
    CURSOR ven_cur IS 
    SELECT *
    FROM VENDOR; 
 begin 
    FOR  ven_REC in ven_CUR
    LOOP 
    if ven_REC.VENOR_NAME = 'DELL' then 
    V_NAME:= ven_REC.VENDOR_EMAIL;
    ELSIF ven_REC.VENOR_NAME = 'HP' then 
    V_NAME:= ven_REC.VENDOR_EMAIL;
      ELSIF ven_REC.VENOR_NAME = 'ACER' then 
    V_NAME:= ven_REC.VENDOR_EMAIL;
     END IF;
     end loop; 
 END; 
/
EXIT;
EOF'
echo $RET_VALUE

Please help me.

Thanks.

---------- Post updated 05-26-15 at 11:30 AM ---------- Previous update was 05-25-15 at 07:22 PM ----------

Hi All,

Could you please help me.

Thanks.

Last edited by ROCK_PLSQL; 05-25-2015 at 11:02 AM..
# 4  
Old 05-26-2015
try this ...

Code:
$ cat fileNames
stock_dell_file
stock_hp_file
stock_acer_file
stock_nokia_file
stock_sony_file

$ cat dbvendorName
DELL        surendra@dell.com
HP          rajkamal@hp.com
ACER        sumathi@acer.com
NOKIA       kunal@nokia.com
SONY        sinu@sony.com

$ while read attchedFile
do
vendor=$(echo $attchedFile | awk -F"_" '{print $2}' )
mailID=$(grep -iw $vendor dbvendorName | awk '{print $2}')
uuencode $attchedFile $attchedFile | mail -s testfile $mailID
done < fileNames

# 5  
Old 05-26-2015
Hi,

Thanks for your code.

This information is not in unix file.
Code:
DELL        surendra@dell.com
HP          rajkamal@hp.com
ACER        sumathi@acer.com
NOKIA       kunal@nokia.com
SONY        sinu@sony.com

This is in databse tables I have to fectch from db.
For this I have written this code.
But it's no working .

PHP Code:
#!/bin/ksh
RET_VALUE 'sqlplus $ORACLE_CONNECTION << EOF
set serveroutput on
  declare 
 V_NAME varchar2(100);
 V_NAME1 varchar2(100);
 V_name2 VARCHAr2(100);
    ven_rec VENDOR%rowtype;
    CURSOR ven_cur IS 
    SELECT *
    FROM VENDOR; 
 begin 
    FOR  ven_REC in ven_CUR
    LOOP 
    if ven_REC.VENOR_NAME = '
DELL' then 
    V_NAME:= ven_REC.VENDOR_EMAIL;
    ELSIF ven_REC.VENOR_NAME = '
HP' then 
    V_NAME:= ven_REC.VENDOR_EMAIL;
      ELSIF ven_REC.VENOR_NAME = '
ACER' then 
    V_NAME:= ven_REC.VENDOR_EMAIL;
     END IF;
     end loop; 
 END; 
/
EXIT;
EOF' 
Please help me.

Thanks.
# 6  
Old 05-26-2015
Hi Rock_PLSQL,
Please try this, Create a file from DB for vendor details.

Code:
$ cat fileNames
stock_dell_file
stock_hp_file
stock_acer_file
stock_nokia_file
stock_sony_file

Script Name - sendmailTovendor.sh
Code:
#!/bin/sh

sqlplus -s $user/$passwrd > dbvendorName <<ENDOFSQL
whenever sqlerror exit sql.sqlcode;
SELECT *  FROM VENDOR;  
exit;
ENDOFSQL

while read attchedFile
do
	vendor=$(echo $attchedFile | awk -F"_" '{print $2}' )
	mailID=$(grep -iw $vendor dbvendorName | awk '{print $2}')
	uuencode $attchedFile $attchedFile | mail -s testfile $mailID
done < fileNames

# 7  
Old 05-26-2015
Hi,

Thanks a lot for your script.
This is sending mails but not attaching files and no subject.

Can you please check this.

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Crontab 2>&1 not emailing

I have a script that emails me when I run it manually, but the crontab I'm using must be 'silencing' the output? Here's what I have: */15 * * * * /usr/src/blah.sh > /dev/null 2>&1 I don't want it to email me every time it runs, just when I run the sendmail command inside the script if the... (13 Replies)
Discussion started by: unclecameron
13 Replies

2. Shell Programming and Scripting

Conditional emailing with mysql query

Hi, Im new with bash scripting and I want to create a conditional emailing with bash scripting. But it doesn't workout. the conditional requirement are; if the TextDecoded value from inbox table are not the same with sms_keyword value from kontak_group table then don't email. It keep... (10 Replies)
Discussion started by: jazzyzha
10 Replies

3. UNIX for Dummies Questions & Answers

Shell script emailing issue

Hi, Im writing a shell script: #!/bin/bash #Send process which has exceeded 25% # echo 'pri pid user nice pcpu command' > /export/home/tjmoore/file2 # if ps -eo pri,pid,user,nice,pcpu,comm | awk '{if($5 >= 25)print $0}' >> /export/home/tjmoore/file2 2>/dev/null # # # then... (1 Reply)
Discussion started by: jay02
1 Replies

4. Shell Programming and Scripting

Help in scripting for emailing notificatons

Hi all, I have a table like this: Name email booking no xyz xyz@abc.com 1235 pqr pqr@abc.com 2536 xyz xyz@abc.com 5896 we have to send a notification to all distinct email ids with consolidated booking information in a single mail. i.e., 1235 2536 with some subject has... (6 Replies)
Discussion started by: dineshnarra
6 Replies

5. Shell Programming and Scripting

emailing as body of email

hi all, how do i email a file in the body of an email rather than as an attachment ?? have a ksh script which i need to read a file and email as part of the body rather than an attachment. my code is : uuencode file.log | mailx -s "test" but this sends file as an attachment. ... (2 Replies)
Discussion started by: cesarNZ
2 Replies

6. Shell Programming and Scripting

script not emailing or running

Hi, I am having trouble with this script. It is suppose to send me an email when the specified tablespace is 60% full. I run it but nothing happens FREESPACELOG=/home/oracle/scripts/bin/free_space/freespace.sql email=bob@bob.edu subject="PROD: Tablespace Free Space" cmd="mailx -s... (1 Reply)
Discussion started by: shaseeb
1 Replies

7. Shell Programming and Scripting

Copying files and emailing them out

Hello everybody, I'm trying to create a script that will cd into a directory and then copy the file with yesterday's date on it and then cd into another directory doing the same thing. Afterwards, i'm trying to zip up the two files, and email them out to people. Can anyone help? thanks a... (1 Reply)
Discussion started by: jhofilena
1 Replies

8. Solaris

Emailing about password expiry for a user

How to create a mechanism that e-mails user/admin before password expiry. Assume 7 days in advance. Thanks in advance for your great help. Regards, Awadhesh (4 Replies)
Discussion started by: Awadhesh
4 Replies

9. UNIX for Dummies Questions & Answers

SMTP - emailing issue

We are running an application engine program that sends email to a list of users. In our Test Env, users are able to receive the emails but in our Prod environment, they do not. We are running the same program, and using the same stmp config. any idea on how to troubleshoot? (3 Replies)
Discussion started by: tads98
3 Replies

10. Shell Programming and Scripting

File contents required for emailing.

I have created three SQL scripts that are run by one central script. What I need to do is verify the output file from the three SQL scripts(KSH Scripts) is worth emailing. This I would like to do by verifiying the contents of the result file. The contrlooing script creates the result file... (6 Replies)
Discussion started by: jagannatha
6 Replies
Login or Register to Ask a Question