mailx command

Hi,

I am seeing that this command is sending mail even when the nawk command in untrue ( does not have any output ). I only want it to send mail, where it goes above the threshold, and has some output.

nawk -F'(MOD dn="uid=)|(DEL dn="uid=)|[,]' '/(MOD dn="uid=)|(DEL dn="uid=)/ {u[$2]++}END{for(i in u) if(u>thr) print "user",i,"has crossed ["u"] the thresold limit ",thr}' thr=100 access | mailx -s 'Thresold Email' TO_EMAIL_ID

Can someone help me on this?

Thanks.

Shouldn't TO_EMAIL_ID be replaced with ${TO_EMAIL_ID} ?

nawk -F'(MOD dn="uid=)|(DEL dn="uid=)|[,]' '/(MOD dn="uid=)|(DEL dn="uid=)/ {u[$2]++}END{for(i in u) if(u>thr) print "user",i,"has crossed ["u"] the thresold limit ",thr}' thr=100 access > mail_body
cnt=$(cat mail_body | wc -l)
if [ $cnt -gt 0 ]
then
   mailx -s 'Thresold Email' TO_EMAIL_ID < mail_body
fi
rm -f mail_body