Hello gsiva
A powerful debugging technique is to break up the code into simpler blocks and see if each block is doing what you think it is doing.
Using this technique, what is the output from
Code:
/var/log/messages | awk '{print $1, $2, +$6}' | sort | uniq -c | sort -nr
If that's doing what you wanted it to do, what is the output from
Code:
/var/log/messages | awk '{print $1, $2, +$6}' | sort | uniq -c | sort -nr >> /root/mailalert
What value(s) will that give to $i? If none then the loop will not be executed. It looks like you're expecting a single number -- so why use a loop?
You may find the wc command useful.
Best
Charles