Cron job to warn you when your quota is almost full
Alec Jacobson
May 11, 2010
When I go over my disk space quota on the CIMS server I'm locked out of my account. I can only issue the ls
and cd
commands. That's right, I can't even issue rm
. Which means every time (I realize it shouldn't happen often but it alas has) I go over the quota I need to call the help desk and have them enlarge my quota temporarily so I can delete some files.
This happened recently over the weekend that we were working on a paper for the SGP deadline and nobody was at the CIMS help desk to answer my desperate call. So from now on I have a little script that will email me when I'm close to filling my quota. Here's the script, which I save in a file called email-quota-warning.sh
:
#!/bin/bash
# grep out percentage of quota used on "home" mount
PERCENT=`quota | grep home | grep -o "[0-9]\+\%" | grep -o "[0-9]\+"`;
# if the percentage is a above some threshold then send an email
if [ "$PERCENT" \> "95" ]; then
MESSAGE="Your quota on home is getting close to full: $PERCENT%";
EMAIL="your-email-goes-here";
SUBJECT="Quota Warning: $PERCENT% full";
echo $MESSAGE | /bin/mail -s "$SUBJECT" "$EMAIL"
echo 'echo $MESSAGE | /bin/mail -s "$SUBJECT" "$EMAIL" '
fi;
Then I set up a cron job on a CIMS machine. Because the access.cims.nyu.edu machine has a bogus version of mail
(I couldn't figure out how to make it do subjects), I set up my job on mauler.
Of course then I had trouble editting my crontab. When I issue:
crontab -e
I get the following error:
E486: Pattern not found: 's$
crontab: no changes made to crontab
I couldn't figure out how to fix this problem so instead I just created a file called .crons
with the following in it:
0 * * * * bash ~/bin/email-quota-warning.sh
Of course change the bash to wherever you're storing the script. Then just issue:
crontab .crons