Script for getting alert when the partition is full
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
[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.
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,
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
...
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.
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
#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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.