#!/BIN/BASH
# To alert whenever lsof crosses 80%
maxlimit=32000
echo 'Max limit is ' $maxlimit
tlimit=$(bc <<< $maxlimit*0.8)
echo 'Treshold limit at 80% ' $tlimit
a=$(lsof | wc -l)
echo 'Current usage ' $a
if [ $(bc <<< "$a > $tlimit") -eq 1 ]
then
echo 'lsof =' $a 'has exceeded 80% of maximum limit' | /usr/bin/Mail -s "ALERT!!!" "*****@cisco.com"
fi
* * * * * bash /root/vasanth/lsef/script.sh
In the above script, the output is to send a mail to the corresponding Mail ID .
When I run it manually it sends the mail.
But, when it is scheduled in cron, the mail is not being sent.
I cant understand what the problem is. How could I debug it?
/usr/bin/Mail?#!/BIN/BASHshould be#!/bin/bash. It won't matter in this specific case because you're explicitly usingbashto run your script, but it will burn you later if you get into this bad habit.bctest succeed? Maybe add atouch /tmp/i_tried_to_send_Mailahead of theecho ... Mailcommand to ensure it's attempting to call Mail. Does the Mail program expect an environment variable to be set in order to succeed?