LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-14-2010, 04:11 AM   #1
dhirendrs
Member
 
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


hi

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.

Regards
Dhiren shah
 
Old 06-14-2010, 04:20 AM   #2
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Rep: Reputation: 62
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.

Code:
#!/bin/bash
CURRENT=$(df / | grep / | awk .{ print $5}. | sed .s/%//g.)
THRESHOLD=90

if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
mail -s "Disk Space Alert" you@mail.com << EOF
Your root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi
 
Old 06-14-2010, 11:50 AM   #3
bskrakes
Member
 
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:

Quote:
print $5
to this:

Quote:
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:
Quote:
df / | grep / | awk "{ print $5}" | sed "s/%//g"
This is what mine returns if I use the "print$5"
Quote:
[root@server ~]# df / | grep / | awk "{ print $5}" | sed "s/%//g"
/dev/mapper/VolGroup00-LogVol00
59514964 17205476 39237488 31 /
But if I switch it to "print$4" is outputs this:
Quote:
[root@server01 ~]# df / | grep / | awk '{ print $4}' | sed 's/%//g'
31
I found out how to do the above from this site Linux Journal.

If you need more help please post back!!
 
  


Reply

Tags
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 11 03-13-2024 06:39 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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:42 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
Open Source Consulting | Domain Registration