LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-22-2009, 05:23 PM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,674

Rep: Reputation: 47
Automatically monitor free space


Is there a way to have the servers send me an email when any of the partitions drop below a certain amount of free disk space?
 
Old 07-22-2009, 05:44 PM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
If you don't need real time, you can design a script that will parse the output of df, and check if the free space is lesser than a given number or percentage, and if affirmative mail you. Then you can put it as a cron job.

You could as well mount the remote drive via nfs, sshfs, samba or whatever fits you, and just monitor it locally with gkrellm, conky or something else.
 
Old 07-22-2009, 06:31 PM   #3
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
Here is one idea that may get going in the right direction. Create a script similar to the following listing:

#!/bin/bash

EMAIL=user@example.com
SUBJECT="WARNING: Disk space low"


df -h | sed 's/%//' | awk '{if ($5 > 19) print $0 }' | mail -s "$SUBJECT" $EMAIL



Change the 19 in the awk statement to be your threshold or upper limit. I used 19 to test an existing partition. Then if this works for you, just setup a cron job to run as often as you need.

Regards,

Fordeck
 
Old 07-23-2009, 09:33 AM   #4
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,674

Original Poster
Rep: Reputation: 47
What's the 19 signify? percentage free space or MB or something?
 
Old 07-23-2009, 09:50 AM   #5
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
be forewarned that if you use a script on the machine to check for diskspace using a cron job that if the disk space fills up in between cron jobs and the partition is the / partition you will not get an alert. Ive had instances where the / filled up and the script apparently needs some tmp space to execute the script and if there is no space left the script will not run. If you have more than one server you can either run a cron job from another server, setting up ssh keys of course or you can use something like nagios to monitor disk space.
 
Old 07-23-2009, 10:25 AM   #6
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,674

Original Poster
Rep: Reputation: 47
I think my / have a good amount of space where I won't have to worry about them filling up. I'm more concerned with the couple data partitions I have. but that's good to know though, I never thought of that.
 
Old 07-23-2009, 07:06 PM   #7
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
Here is an example of the output of the df -h command:

Code:
[user@fs2 ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              38G  8.0G   28G  23% /
/dev/sda1             190M   33M  148M  18% /boot
tmpfs                 752M     0  752M   0% /dev/shm
/dev/sda7             4.8G  145M  4.4G   4% /tmp
Now if you look at the columns of information, the 5th column is the percentage used. What the script does is compare $5 or the 5th column to see if it greater than 19 in this case

$5 > 19

Where 19 is the percentage that I chose as my upper limit for the sake of testing. Because the /dev/sda6 which is mounted on / is at 23% it will trigger an email. You of course will have a number that you want to use for that upper limit rather than 19. The sed command simply removes the % symbol and $5 simply refers to the 5th column of data to see if it is greater than 19.

Code:
#!/bin/bash

EMAIL=user@example.com
SUBJECT="WARNING: Disk space low"


df -h | sed 's/%//' | awk '{if ($5 > 19) print $0 }' | mail -s "$SUBJECT" $EMAIL
Let me know if you have any other questions.

Regards,

Fordeck
 
Old 07-24-2009, 08:59 AM   #8
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,674

Original Poster
Rep: Reputation: 47
OK, I can actually make sense of what that line does now, thanks!
 
Old 07-24-2009, 09:00 AM   #9
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,674

Original Poster
Rep: Reputation: 47
Now I just gotta figure out what to do to setup email on the server haha.
 
Old 07-24-2009, 09:59 AM   #10
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
all you should need is sendmail and to make sure its running.

Last edited by ncsuapex; 07-24-2009 at 10:13 AM. Reason: .
 
Old 07-24-2009, 10:11 AM   #11
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,674

Original Poster
Rep: Reputation: 47
thanks!
 
Old 07-24-2009, 12:37 PM   #12
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
To see if sendmail is installed you could run the following command:

rpm -qa | grep sendmail

If it is installed you should see something similar to the this:

Code:
[user@fs2 ~]# rpm -qa | grep sendmail
sendmail-8.13.8-2.el5
sendmail-cf-8.13.8-2.el5
If it is installed then check to see if it is set to start up automatically by running the following command:

chkconfig --list | grep sendmail

This will show output similar to:

Code:
[user@fs2 ~]# chkconfig --list | grep sendmail
sendmail       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
The above output is from a CentOS 5.3 Final server that has sendmail running on it. If you are still unable to get the disk space script to send an email you may have to look at what your firewall could possibly be blocking. Post any other questions you might have.

Regards,

Fordeck
 
Old 07-24-2009, 04:48 PM   #13
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,674

Original Poster
Rep: Reputation: 47
thanks, i'll check it out
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help removing free space to create Raw free space nightmare55 Linux - Newbie 11 10-01-2009 04:07 AM
How to automatically disable dual monitor setup when only one monitor is present NielsKM Linux - Laptop and Netbook 1 01-01-2008 12:17 PM
Not enough free space on hard drive with 50g of free space??? auoq SUSE / openSUSE 5 10-13-2004 09:21 PM
Not enough space for root directory on a drive with 50g free space??? auoq Linux - Newbie 1 10-13-2004 01:44 PM
Formating free space: WinXP pro and RH9 dualboot with free space on 3rd drive Vermicious Linux - General 2 03-22-2004 06:10 AM


All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration