Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 and do the needful?

share|improve this question

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



share|improve this answer
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
@gertvdijk No, it's ok with df -P, it's designed to be easily parsable (except when device names can contain whitespace). – Gilles Dec 24 '12 at 17:35
@Gilles Good to know that, thanks! – gertvdijk Dec 24 '12 at 18:13

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. $?.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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