Problem with if logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with if logic
# 1  
Old 02-08-2006
Problem with if logic

Hi there,
In my shell program I have two if statements
the first one checks that the date in yyyymm format is equal to a date from the parameter file in yyyymm format, and that the file and sends an appropiate email

The second one checks that the date in yyyymm format is equal to a date from the parameter file in yyyymm format, and that the new file size is greater the the previous file size and sends an appropiate email


The problem I have is that I get BOTH emails sent; below is the code and the values of the variables - can anyone see what I have done wrong
#month is same but file bigger new data so mail

if [ $cursize -ge $prvsize -a $curdate -eq $prvdate ]; then
subject="New Three Hour Calls for `date +%b %Y`"
mail_report $REPORTTXT
fi

#Month and file size are the same warning email no file send

if [ $cursize -eq $prvsize -a $curdate -eq $prvdate ]; then
echo "In same data email clause"
subject="No New Three Hour Calls for `date +%b%Y`"
mail_report $REPORTTXT

Current month date is 200602 - curdate
Previous Size is 417 - prvsize
Current Size is 417 - cursize
PRevious month date is 200602 - prvdate


An ideas as to what I'm doing wrong
# 2  
Old 02-08-2006
yes you will get both the emails because prv size and cur size is same...

in the first condition, you are checking greaer than or equal.... here both are equal hence condition matching...

in the second if condition, you are just checking equal... here both are equal hence condition matching...

I think you need to remove -ge and replace -gt
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk if logic problem

nawk '{ fmt="%3s %22s %48s %35s %21s\n"; if ($3==$6 && $1=="STOPLOSS") { tpy="Successful Match"; jnme=$1; sts="File will be loaded"; cntrl=$3; audit=$6; printf (fmt, tpy,jnme,sts,cntrl,audit) >> "'${AUDIT_DATA_FILE}/${AUDIT36}'" }else if ($3!=$6 && $1=="STOPLOSS") { tpy="Mis-Match ";... (4 Replies)
Discussion started by: wawa
4 Replies

2. UNIX for Dummies Questions & Answers

if then else logic with while loop problem

Hi Friends, I have to do write a shell file based on one flag.If that flag value is 'N' then process look in $DATA are and the normal process continue.If vaule is 'P' then it check for the files in different location $CONV and move those file in $DATA area and rest of the process... (2 Replies)
Discussion started by: Param0073
2 Replies

3. Shell Programming and Scripting

Please help me to figure out the logic for this problem

Hello, i am on 2.6.13-1.1526_FC4smp i have directory named /home , and in there i have directory 2009_10_10 and two files : 2009_10_10.log and 2009_10_11.log How to write shell script which will delete only file/s that don't have his/their 'parent' directory, so in this case , only... (7 Replies)
Discussion started by: tonijel
7 Replies
Login or Register to Ask a Question