1

I have a similar question. I tried iWatch but ATM it doesnt seem to email me. but also i dont believe it will watch disk space. That isnt advertise on their homepage.

What app can i use to email me when the disk is getting low? Can i use the same app to watch folders for filechanges? (and exclude a subfolder such as lucene which is expected to change)

3 Answers 3

2

In a former life without monitoring systems and automatic warnings I had use for this snippet:

#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while
read output;
do
  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge 90 ]; then
      echo "Running out of space \"$partition ($usep%)\" on $(hostname)
      as on $(date)" |
      mail -s "Alert: Almost out of disk space $usep%" [email protected]
   fi
done

If you are monitoring more than just this server, make yourself and your company a big favour and use a proper monitoring server like nagios. We use opsview community edition because it is free like nagios and has a great web interface so you do not need to be a linux admin to add/remove hosts/services.

2
  • I am using nagios. It looks good. I tried opsview as well. It doesnt seem to play well with debian lenny (i followed the instructions) and had unresolved lib problems. Also it looked like it requires java. I dont want to use java on my server only for one app (which will be the case ATM since i have no others).
    – user274
    Sep 30, 2010 at 0:49
  • I have had absolutely no problems using the opsview repository downloads.opsera.com/opsview/apt/community and installing opsview in debian lenny. It does install the java runtime environment, but I do not find that disturbing. I have used nagios since version 2, and I love the product, but being the only admin that is able/willing to administer the monitoring system will finally have your nagios server cancelled. Having a nice web ui gives your colleagues no excuse not to use it. Sep 30, 2010 at 9:19
1

One-liner for cron:

MAXUSE=`df |sed 's/^.* \([0-9][0-9]*\)%.*$/\1/g' \
  |sort -nr \
  |head -1` \
  sh -c 'if [[ ${MAXUSE} > 95 ]]; then echo "Usage at ${MAXUSE}%"; fi'

Note that cron only e-mails when there is output. So a cron script that runs but prints nothing will trigger no e-mails.

2
  • i didnt know linux hacking can be that easy! unfortunately theres an error in that script and i dont know how to fix it. I tried for 5mins now so i'll instead try to write it in a normal bash file.
    – user274
    Sep 29, 2010 at 9:34
  • you cannot use [[ ]] with sh , you have to use [ ] , or use bash if you want [[ ]] Jan 2, 2021 at 2:52
0

You can probably script something together using cron and incron

1
  • 1
    I dont want to code yet another solution.
    – user274
    Sep 29, 2010 at 8:57

You must log in to answer this question.