Sponsored Content
Top Forums Shell Programming and Scripting Sending an Automated Mail with a Condition Post 302878244 by Sreenadh on Thursday 5th of December 2013 08:09:25 AM
Old 12-05-2013
Code:
#!/bin/ksh
#Initial Variables
IFILE="$HOME/bday.csv"
OFILE="bday_out"$$
MAILID="abc@xxx.com"
#get today's date & month
DAT=`(date '+%d')`
DAY=`(date '+%a')`
MON=`(date '+%b')`
while IFS=',' read name date day month year
do
set -x
if [ "$date" -eq "$DAT" -a "$day" = "$DAY" -a "$month" = "$MON" ]
set +x
   then echo $name
   fi
done < $IFILE > $OFILE
set -x
if [ -f $OFILE -a -s $OFILE ]
set +x
then
   sed -i '1i The following users celebrate their birthday:\n' $OFILE
   mailx -s "Birthday on: $DAT" $MAILID  < $OFILE
  # \rm $OFILE
   echo "Birthday mail sent"
else
   echo "No birthdays today"
fi

This is the code i am executing & i am trying this in my office, dont have bash here! Smilie

---------- Post updated at 08:08 AM ---------- Previous update was at 08:04 AM ----------

---------- Post updated at 08:09 AM ---------- Previous update was at 08:08 AM ----------

Quote:
Originally Posted by zozoo
try this
Code:
if  [[ "$date" -eq "$DAT" && "$day" = "$DAY" &&  "$month" = "$MON" ]] ; then

---------- Post updated at 05:15 PM ---------- Previous update was at 04:53 PM ----------

please find below test snippet

Code:
 
/var/backup # cat test.sh                                                         
while IFS=',' read i j k                                                        
do                                                                              
if [[ $i -eq "06" && $j = '12' && $k = '2013' ]];                               
then                                                                            
echo $i >> new.txt                                                              
fi                                                                              
done < input                                                                    
/var/backup # cat input                                                           
06,12,2013                                                                      
/var/backup # ./test.sh                                                           
/var/backup # cat new.txt                                                         
06                                                                              
/var/backup #


Tried this IF condition buddy, but still the result is same Smilie
Is it because i am executing it in Ksh ? i cant do it in bash though!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sending a mail to a mail client

Hi everyone! I'm trying to create a database monitoring script that reads an alert file and sends an error message if it can 'grep' a particular string. Is there a way to send this message to a mail client using SMTP? Even better, is there any place on this site that has these kinds of... (5 Replies)
Discussion started by: solaris73
5 Replies

2. UNIX for Advanced & Expert Users

sending mail

How do I send an email with a subject and an attachment from a command prompt? (3 Replies)
Discussion started by: mskarica
3 Replies

3. UNIX for Dummies Questions & Answers

Sending Mail

Please help me out i want to know how to send email from unix machine to any email-id. mail to be sent is web based mail. (1 Reply)
Discussion started by: parmeet
1 Replies

4. HP-UX

Sending mail thru HP-UX

I got stuckup with the issue of sending mail with attachment from HP-UX. Can any one please help me in resolving the issue. I am giving the criteria which i want below, 1. To address. 2. Cc address. 3. Subject 4. File attachment(the file i am using is :-- filename_`date +%Y%m%d`.CSV)... (1 Reply)
Discussion started by: medisetti
1 Replies

5. HP-UX

hp ux not sending mail

Hi.. In Hp ux box,, mails are not being sent. they are getting queued up in mail queue. (3 Replies)
Discussion started by: kkhan
3 Replies

6. Filesystems, Disks and Memory

Sending mail

Hi, I am want to send mails from my aix server using smtp adaptors.How to configure this? i tried with send mail command but it is failing,but what i try with my localhost(my desktop which is not using the aix server) machine i can send mails using the smtp adaptor(simply type telnet... (0 Replies)
Discussion started by: gnanadurai_it
0 Replies

7. UNIX for Dummies Questions & Answers

sending mail

i want to send an email from the unix machine to the windows machine. now windows dont have any specified folder for the mail. mail has to be sent to the email-id like abc@xyz.com unix machine itself can not directly send mail. it has to be transferred via mail server. (11 Replies)
Discussion started by: parmeet
11 Replies

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

9. Shell Programming and Scripting

if condition in sending mail

hello Gurus i have tp tackle a condition like below I have two files to check for any data in it apart from header if one of the file has data I have to send mail given the file name So far my code is if || ; then (printf "%s\n%s\n" "Please check the below bad files: "... (2 Replies)
Discussion started by: Pratik4891
2 Replies

10. 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
All times are GMT -4. The time now is 12:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy