#!/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
? – Archemar Sep 08 '17 at 13:45#!/BIN/BASH
should be#!/bin/bash
. It won't matter in this specific case because you're explicitly usingbash
to run your script, but it will burn you later if you get into this bad habit. – Chris Davies Sep 08 '17 at 14:35crontab
? (If you edited a file, which one did you edit?) – Chris Davies Sep 08 '17 at 14:37* * * * * /bin/bash /root/vasanth/lsef/script.sh
– Philippos Sep 08 '17 at 14:49bc
test succeed? Maybe add atouch /tmp/i_tried_to_send_Mail
ahead of theecho ... Mail
command to ensure it's attempting to call Mail. Does the Mail program expect an environment variable to be set in order to succeed? – Jeff Schaller Sep 08 '17 at 16:20