Send email if the condition matches


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Send email if the condition matches
# 1  
Old 04-20-2012
Send email if the condition matches

Hello everyone,

I am trying to create function or script to send email from an address book file.

Here is the file format i have,

Code:
     Susan:Miller:M:123 Main Street:Philadelphia:PA:17101:666-645-6666:Susan.Miller@gmail.com:07/12/1979 Robert:Langan:S:32 North Avenue:San Francisco:CA:17011:717-212-8833:robert.langan@msn.com:06/06/1980

In script i have to send an email to people in the address book file whose birthday is today.

Code:
     awk -F":" '{ print $9, $10}' myaddress Susan.Miller@gmail.com 07/12/1979 robert.langan@msn.com 06/06/1980

gives me column i need it but i am not sure how can i convert those fields into a variable then pass it to mail command while adding the following conditions
if birth day is equal to system date then for each contact send email.

Code:
     echo $EMAILMESSAGE | /bin/mail -s “$SUBJECT” “$EMAIL”

any idea and sample script greatly appreciated.

Thank you.
# 2  
Old 04-20-2012
It seems very like a homework exercise this........., but.......

You may have a problem if you data really is one long string. If it is actually separate records then you can read the output from your awk

Code:
awk -F":" .........whatever ........ | while read EMAIL next1 next2 rest
do
   echo $EMAILMESSAGE | /bin/mail -s "$SUBJECT" "$EMAIL
done


I'm not sure what output you expect to get and use from your awk


I hope that this helps a little to get you started


Robin
Liverpool/lackburn
UK

Last edited by rbatte1; 04-20-2012 at 10:45 AM.. Reason: Take off erroneous bold highlight
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 04-20-2012
umm thank you rbatte1, yes it is a homework assignment and I am struggling a little bit.

my awk statement;
Code:
awk -F":" '{ print $9, $10}' myaddress
 Susan.Miller@gmail.com 07/12/1979
 robert.langan@msn.com 06/06/1980

how do you compare the system date day and month within $10 output? is day and month matches in $10 then do this etc.
Does it make sense?
# 4  
Old 04-20-2012
Probably best if you read the manual pages for test and date

If you are panicking that I mean to go to the library and get the books out, there are manuals normally installed by default:-
Code:
man test

then
Code:
man date

I could just code it up, but then you won't learn. Have a go and let us know how you get on. Try to think of the logic how you would do it on paper, remember you cannot assume that the machine knows anything, but it can look it up, including the system date.

If you've been trying and have some examples that show what's going wrong, then people will be happy to help, I'm sure.



Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 04-20-2012
rbatte1, I agree with you. thank you for pointing me the right direction. I think i come up with this solution for now. I am not sure it is the best way to do it but it seems like working OK for now .

Code:
today=`date '+%m/%d/'`
$(cat filename | grep $today | awk -F: '{print $9}')

then use for each loop to send email.

Last edited by asistant; 04-21-2012 at 12:36 AM..
# 6  
Old 04-22-2012
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a text and if condition matches then replace it

Need a script that can find text in a file and replace it accordingly. This is the file I have: while IFS=',' read -r f1 f2 f3 do { nohup /home/testuser/dbmaintenance/sys_offline_maintenance.sh $f1 $f2 $f3 > $f2.out & } done < "/home/testuser/dbmaintenance/week1offlineserver.txt" In... (4 Replies)
Discussion started by: singhhe
4 Replies

2. Shell Programming and Scripting

Grepping only if condition matches

Dear Friends, I have a flat file which is as follows $cat sample 123,456,1,1,1,1 sdfas,345,1,1,1,1 dfgd,234,2,3,4,1 ggffgr,234,4,3,2,1 jkhu,354.1,1,1,1 $ I want to get output of only those lines which has '1' in 3 to 5 position. So I want output as follows 123,456,1,1,1,1... (8 Replies)
Discussion started by: anushree.a
8 Replies

3. SuSE

Send outgoing email to my GroupWise email

Dear users, I have Linux server whose versions are Suse 10 SP 3 and Suse 11. I am trying to send email from these servers to my GroupWise email account. In /etc/postfix/main.cf file, The current value of MYHOSTNAME is LINUX.LOCAL. What should be the right value of MYHOSTNAME? Is... (0 Replies)
Discussion started by: JDBA
0 Replies

4. UNIX for Dummies Questions & Answers

new to ldap, send email to a ou or group, and see a list from email client

hi, i'm running openldap on ubuntu 10.04, creating new items with apache directory studio (windows version). i use the ldap just as an address book to our small office (email clients are windows live mail 2009, 2011, microsoft outlook 2007 and 2010). a. i cant see a list of the contacts,... (0 Replies)
Discussion started by: V4705
0 Replies

5. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

6. Solaris

Send an email from Solaris using Linux email server

Hello everyone I have a problem and I need your help: I have a Solaris 10 and Solaris 8 UNIX Servers, and Linux Centos4 as email server. I need send an email from Solaris servers preferably using Centos4 email server. I have no mail service configured in my Solaris computers (1 Reply)
Discussion started by: aflores
1 Replies

7. Shell Programming and Scripting

Send email to user when condition met

Hi all, I plan to write a shell script to inform users on their task when certain condition met. example: If a then email user on action a else email user on action b. I'm pretty new in scripting, appreciate any suggestions. Thanks. (4 Replies)
Discussion started by: *Jess*
4 Replies

8. UNIX for Dummies Questions & Answers

Send email where # is in the email address - Using Unix

Hi All, How do I send an email using malix where email address contains a #. I have a email address like this : #test@test.com I want to send email like malix -s "TEST" #test@test.com < SOMEFILE I tried \# but doesn't work. Please let me know how we can achieve this? I am in... (1 Reply)
Discussion started by: jingi1234
1 Replies

9. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies
Login or Register to Ask a Question