A script where we need to come up with a way for the disk space monitoring to be smarter. On smaller file systems, we still want to alert at 90% full, but on larger file sytems, we should only alert when there is only a few GB free.

Can someone please shed some light on this?


There is multiple options, but you need modify below script as per your requirement.

#!/usr/bin/awk -f
"date" | getline date
"uname -n" | getline hostname

    while("LC_ALL=C df -Ph" | getline){
            if($1 != "Filesystem" && int(used) >= threshold){
            print "Running out of space: "$1,used" used on "hostname" as on: "date
            print "mail -s \"Alert: Almost out of disk space: " $1,used" used\" "ADMIN" >/dev/null" | "sh"

You can refer below links http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html



  • 2
    Parsing the lines of df will break as soon as the mount reaches a certain amount of characters that df will print it on multiple lines. – gertvdijk Dec 24 '12 at 8:23
  • 1
    @gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace). – Gilles 'SO- stop being evil' Dec 24 '12 at 17:35

You could (ab)use the Nagios plugin check_disk for this. The advantage is that this piece of software is lightweight, well-tested and probably available by your package management already (Debian/Ubuntu package nagios-plugins-basic). Example usage:

check_disk -w 10% -c 3 -u GB -p / -p /mnt

In this example, it checks two mointpoints / and /mnt. If it exits with a exit status of 2, your disk has less than 3GB available, if it exits with status 1, it has less than 10% available and if it exits with a status of 0, then neither of the values is reached. Checking for exit status in Bash is trivial, i.e. $?.

  • Thanks for your advice.yes we can do it with check_disk nagios plugin. But I would like to write it in shell scripting. – user29218 Dec 24 '12 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.