LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 01-12-2010, 04:33 PM   #1
arooooon
LQ Newbie
 
Registered: Nov 2009
Location: Chennai,India
Distribution: RHEL 5.0, MAC
Posts: 11

Rep: Reputation: 0
Question Script for getting alert when the partition is full


Hi Techies..

Is it possible to write a script for getting an automatic alert when a particular partition is full ?

Should we use crontab for this ?

Is any template is available in net for above scenario ? If so, pls give me the URL.

---
ARUN
 
Old 01-12-2010, 05:48 PM   #2
SaintDanBert
Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-11, v11.04 Ubuntu & Kubuntu
Posts: 935
Blog Entries: 3

Rep: Reputation: 51
Quote:
Originally Posted by arooooon View Post
[SIZE=4]
Is it possible to write a script for getting an automatic alert when a particular partition is full ?
Decide what you want from the script.
==>yes/no, true/false, error/success ... the partition is full

==> NNN % ... the partition is some percentage full

... or something else.

Use the df OPTION FILESYSTEM command to get a report on "free disk space" to standard output. Here is a script fragment:
Code:
user@host:$/Prj$ df -h /var
Filesystem Size Used Avail Use% Mounted on 
/dev/sda8  9.2G 877M 7.9G   10% /var

user@host:~/Prj$ foo=$(df -h /var)
user@host:~/Prj$ echo $foo
Filesystem Size Used Avail Use% Mounted on /dev/sda8 9.2G 877M 7.9G 10% /var
user@host:~/Prj$
The value of variable foo contains two records as one string.
The first record is column titles. The second record is the data.
Next write your code to parse the string for the numbers you want.

Once you have a running script to ask your question, embed this script into another script to (1) ask your question, and (2) report however you want to report.

Good luck,
~~~ 0;-Dan
 
1 members found this post helpful.
Old 01-13-2010, 11:42 AM   #3
arooooon
LQ Newbie
 
Registered: Nov 2009
Location: Chennai,India
Distribution: RHEL 5.0, MAC
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks Dan

Hi Dan,

I'm able to understand somewhat, as i'm just started learning about scripts...plz give me any link for learning about scripts from the scratch and thank you very much for your reply

---
ARUN
 
Old 01-13-2010, 11:57 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,610
Blog Entries: 47

Rep: Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://www.tldp.org/LDP/abs/html/ <- save this one for last, OK?
 
1 members found this post helpful.
Old 01-14-2010, 01:40 PM   #5
infinitiguy
LQ Newbie
 
Registered: Feb 2008
Posts: 10

Rep: Reputation: 1
Arun,
let me know how you get on with the script. I wrote a script a while back that does this, although it lacks some intelligence. i.e. it'll mail you on every cronrun until you fix the disk space issue.

if you get stuck, I may be able to help.
Cheers,
-Derek
 
Old 01-15-2010, 12:22 AM   #6
arooooon
LQ Newbie
 
Registered: Nov 2009
Location: Chennai,India
Distribution: RHEL 5.0, MAC
Posts: 11

Original Poster
Rep: Reputation: 0
Sure Derek,i'll ..thanks
 
Old 01-16-2010, 03:33 AM   #7
SaintDanBert
Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-11, v11.04 Ubuntu & Kubuntu
Posts: 935
Blog Entries: 3

Rep: Reputation: 51
Quote:
Originally Posted by infinitiguy View Post
...
I wrote a script a while back that does this, although it lacks some intelligence.
...
Perhaps you could post your script for all to see...?

NOTE to readers:
If 'infinityguy' posts a script remember that any critique might best apply to the code and not the coder. We are all learning something.
He gets two gold stars for free: (1) writing the script, (2)posting it for the lions and other beasties to chew on.

~~~ 0;-Dan
 
Old 01-16-2010, 05:15 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,610
Blog Entries: 47

Rep: Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413
Without pretty printing, checking for empty emails or repeated warnings a /etc/cron.hourly entry for local storage could be as simple as
Code:
THRESH=75; /bin/df -mh | awk '/\/dev\/[h,s]d/ {print $1, $5, $6}' | while read partition percentage mountpoint; do [ ${percentage//\%/} -ge $THRESH ] && echo "$mountpoint $percentage"; done | mail -s "Storage warning for ${HOSTNAME}" rec@pi.ent
 
Old 01-17-2010, 08:58 AM   #9
infinitiguy
LQ Newbie
 
Registered: Feb 2008
Posts: 10

Rep: Reputation: 1
Quote:
Originally Posted by SaintDanBert View Post
Perhaps you could post your script for all to see...?

NOTE to readers:
If 'infinityguy' posts a script remember that any critique might best apply to the code and not the coder. We are all learning something.
He gets two gold stars for free: (1) writing the script, (2)posting it for the lions and other beasties to chew on.

~~~ 0;-Dan
#!/usr/local/bin/bash
#This defines the disk useage for said partition (i.e. it's checking /'s useage, and stripping out everything but the integer

root=`df -F ext3 -k | grep -vE '^Filesystem|tmpfs|cdrom' | grep /dev/sda3 | awk '{ print $5}' | cut -d'%' -f1`

#defines the partiion name we're alerting on
partition=/
#sets threshold
if [ $root -ge 90 ]; then
#emails alert
echo "Running out of space \"$partition ($root%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space on $(hostname). $partition is at $root%" dmurphy@domain.com
fi
exit 0

Here we go. It's really just a single command and then an if statement.
This was when I first started scripting

Hope it helps someone.
 
  


Reply

Tags
alert


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
General Partitioning Limits: How full is too full to partition? orangesky Linux - Hardware 1 12-05-2009 06:27 PM
script for disk space alert cmontr Programming 2 01-12-2009 12:27 PM
oracle alert log script dxangel Programming 3 11-20-2008 01:28 PM
Shutdown script possible to alert about connected USB devices? Roy Prins Linux - Newbie 6 07-23-2008 06:47 AM
Shell script for password expiry alert bhandu Linux - General 1 06-13-2007 04:19 AM


All times are GMT -5. The time now is 04:57 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration