Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-14-2010, 04:11 AM   #1
Registered: Nov 2009
Posts: 45

Rep: Reputation: 15
Smile Linux base shell script with java which check the disk space and send mail to my id


i want to write the script which check the disk space of linux server and send me the disk space details and mail me on my id.

Dhiren shah
Old 06-14-2010, 04:20 AM   #2
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 394

Rep: Reputation: 61
Don't suppose you could show what you've tried so far? Or this is simply a demand for code? Not even a please?

<sigh>....just this once, then.

CURRENT=$(df / | grep / | awk .{ print $5}. | sed .s/%//g.)

if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
mail -s "Disk Space Alert" << EOF
Your root partition remaining free space is critically low. Used: $CURRENT%
Old 06-14-2010, 11:50 AM   #3
Registered: Sep 2006
Location: Canada, Alberta
Distribution: RHEL 4 and up, CentOS 5.x, Fedora Core 5 and up, Ubuntu 8 and up
Posts: 251

Rep: Reputation: 32
Arrow Disk Capacity Check and Email

Hi dhirendrs,

Depending on your hard drive/parition/volume groups setup/configuration you may have to change the command slightly, more specifically the "print$#" part of the command:

print $5
to this:

print $4
The print command is outputting part of the string which is returned by the grep of df, if your configuration is not standard (like mine as I use volumes groups) you will need to change the "print $#". You can test the command by running the following:
df / | grep / | awk "{ print $5}" | sed "s/%//g"
This is what mine returns if I use the "print$5"
[root@server ~]# df / | grep / | awk "{ print $5}" | sed "s/%//g"
59514964 17205476 39237488 31 /
But if I switch it to "print$4" is outputs this:
[root@server01 ~]# df / | grep / | awk '{ print $4}' | sed 's/%//g'
I found out how to do the above from this site Linux Journal.

If you need more help please post back!!


linux, shell

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
How to check and use unpartitioned space of Hard disk in linux. nhsarvaiya Linux - Hardware 10 09-17-2014 09:42 AM
Need a script which does Health check for Linux and send mail notification? your_shadow03 Linux - Newbie 6 11-26-2009 06:20 PM
[SOLVED] Shell script to monitor or watch the disk space.... small help needed vikas027 Programming 5 10-21-2007 10:04 AM
LXer: Perl script to monitor disk space and send an email alert LXer Syndicated Linux News 1 02-23-2007 01:12 PM
SCRIPT: check free space on partition base markus1982 Linux - Software 0 05-25-2003 05:52 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:19 AM.

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