Help on IF


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on IF
# 1  
Old 01-12-2009
Help on IF

I have a script which looks for two counts (one for today and one for the previous day) if today count is less than yesterdays count to email a check error. see below:

function:

current_members_error()

{
if [ $current_members -lt $MEMBERS_COUNT ]
then
ATTENTION="YES-WARNING *CHECK DATA*"
ATTENTION_REQUIRED="ON"
mailx -r $MAIL_FROM -s "**WARNING: ERROR CHECK**" email address < $MSG_DEST_COUNTS
fi

}

script:

ATTENTION="NON"

OFS=$IFS
IFS=","
while read MEMBERS_COUNT MEMBERS_FILENAME
do

ATTENTION="NON"
#Count todays members
current_members=`wc -l ${DATA_DIR}/$MEMBERS_FILENAME | nawk '{ printf "%d\n", $0}'`
current_members_error

done < $PREV_COUNT
IFS=$OFS

What i want to do is only email me when the count is a different by a 1000? i'm sure you do this in the function where i do the less than but not sure how to do it?

any help would be appreciated
# 2  
Old 01-12-2009
subtract the two values,

let newval=$val1-$val2

remove the "-" if the number is negativ, for example with

echo $newval | sed 's/-//g'

and check if it's greater then 999 (-gt)
# 3  
Old 01-12-2009
I don't think this will give me what i want

if the previous day is 32000 and today is 31000

I want it to email me and terminate.

If the figures are previous day is 32000 and today is 31999

don't bother emailing me?

With my above script can i say:

if [ $current_members -lt $MEMBERS_COUNT **and members_count is 1000 less current members** ]

then email

Just not sure of code between ** **?
# 4  
Old 01-12-2009
Quote:
Originally Posted by Pablo_beezo
I don't think this will give me what i want

if the previous day is 32000 and today is 31000

I want it to email me and terminate.

If the figures are previous day is 32000 and today is 31999

don't bother emailing me?

With my above script can i say:

if [ $current_members -lt $MEMBERS_COUNT **and members_count is 1000 less current members** ]

then email

Just not sure of code between ** **?
Code:
if [ $(( $current_members - $MEMBERS_COUNT )) -eq 1000 ]; then
  : ...whatever
fi

# 5  
Old 01-13-2009
thanks for the posts i did it this way:

current_members_error()

{
if [ $current_members -lt $MEMBERS_COUNT ]
then
diff_mem_count=`expr $MEMBERS_COUNT - $current_members`
if [ $diff_mem_count -ge "1000" ]
then
ATTENTION="YES-WARNING *CHECK DATA*"
ATTENTION_REQUIRED="ON"
fi
fi

}
# 6  
Old 01-13-2009
Quote:
Originally Posted by Pablo_beezo
thanks for the posts i did it this way:
Code:
current_members_error()
{
   if [ $current_members -lt $MEMBERS_COUNT ]
   then
       diff_mem_count=`expr $MEMBERS_COUNT - $current_members`


Why are you using expr? The shell can do integer arithmetic:

Code:
diff_mem_count=$(( $MEMBERS_COUNT - $current_members ))

Quote:
Code:
       if [ $diff_mem_count -ge "1000" ]
       then
       ATTENTION="YES-WARNING *CHECK DATA*"
       ATTENTION_REQUIRED="ON"
       fi
   fi

}

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question