0

When I used to use cPanel it would send me an email when any partitions were approaching full. Is there a script out there that monitors df output that I can put in a cronjob?

Thanks

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
Tom
  • 1,055
  • 2
  • 14
  • 21

4 Answers4

0

Try,

# cat partchek.sh
#!/bin/bash
a=$(/bin/df -h | grep /tmp |awk '{print $5}' | awk -F% '{print $1}')
if [ $a -ge 90 ]  // if /tmp full greater than or equal to 90%
then
/bin/mail -s "Kindly check the server: `hostname -i` 's /tmp Partition, Its almost full" your@emailid.here
fi

Add below line in crontab:

 * * * * * /bin/sh /path/for/partchek.sh > /dev/null 2>&1

(This is just an example for /tmp, you can edit for "/" and which you require)

Thanks.

Ranjithkumar T
  • 1,886
  • 16
  • 21
0

don't know if there's already one, but it's not too hard to write. Just put this into your crontab:

df | awk 'NR>1 && $5>80 {print $1 " " $5}'

You should replace 80 with the threshold (percent used) you want to be alerted on. If will mail you the df output for all partitions that cross that usage level.

bluesmoon
  • 3,918
  • 3
  • 25
  • 30
  • This is exactly what I want, but your code seems to output false positives. e.g $ df | awk 'NR>1 && $5>80 {print $1 " " $5}' /dev/sdb1 9% – Tom Jul 16 '10 at 01:27
  • typecast $5 to int: `df | awk 'NR>1 && int($5)>80 {print $1 " " $5}'` – bluesmoon Jul 16 '10 at 07:08
0

It's way overkill for this application, but Nagios monitors disk usage and can email you alerts.

eswald
  • 8,368
  • 4
  • 28
  • 28
0

Nagios does this (and pretty much everything else). If you're setting up a server, it's a good thing to set up. If this is just for personal use, Nagios is probably overkill.

Ken
  • 123
  • 1
  • 9