How to configure in crontab with condition statement for checks

1

We like to monitor the NAS storage mounted on a Linux box. We only like to be notified via mail when the usage exceeds a certain number, say 80. We have only seen in Linux books where most of them are calling shell scripts at certain times.

How do we write inside crontab to only mail us if it exceeds 80 ?

Usual eg

2 2 * * * /home/someUser/script.sh 2>&1 | mail me@me.com

Looking for solution like below

2 2 * * * if [ someNumber > "80" ] ; then /home/someUser/script.sh | mail me@me.com

chz

Posted 2013-10-28T08:39:56.490

Reputation: 339

3Doing this type of thing in the crontab command line isn't necessary, given that you are running a script. Just test the someNumber value inside the script.sh and do the notification if needed. You can do the mail from inside the script too, rather than trying to put it all into the cron line. – Paul – 2013-10-28T08:48:49.960

Answers

1

Your shell script should only 'echo' when conditions meet that you want to be mailed about. Cron sends mail by itself, but only if there is output. Cron mails based on the MAILTO variable. Cron orders your script when to run. When do you sit at your desk? 2AM? I would prefer weekdays after lunch, therefore my crontab file would have:

MAILTO="me@me.com"
35 13 * * 1-5 /home/someUser/script.sh

bbaassssiiee

Posted 2013-10-28T08:39:56.490

Reputation: 1 225