Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 02-14-2013, 04:17 PM   #1
LQ Newbie
Registered: Mar 2011
Posts: 14

Rep: Reputation: 0
Scripting for disk usage of filesystems.

Could somebody kind of walk me through the following? What areas would one study to get a handle on what the below requirements are?

This is for disk usage.

I have had one course in Linux/Unix. I have had C programming.
Is Bash ok to use?

Create a script that sends an email message to the user specified on the command line if any of the filesystems are at more than 70% of capacity. The script should not process special filesystems as /proc . It should only process filesystems which are either locally mounted or are mounted via NFS.
An individual email should be sent for each filesystem which is at the warning level. There should be a subject on the email with a message "Warning: Filesystem <put filesystem the>here is at <X>% of capacity" If the filesystem is at greater than 90% of capacity, the "Warning" should be changed to "Critical Warning".
Old 02-14-2013, 04:24 PM   #2
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,569

Rep: Reputation: 2130Reputation: 2130Reputation: 2130Reputation: 2130Reputation: 2130Reputation: 2130Reputation: 2130Reputation: 2130Reputation: 2130Reputation: 2130Reputation: 2130
Bash would be fine. "df" will already report the disk usage for all mounted filesystems, along with % usage. So it should just be a matter of calling df, and then parsing the output and checking for any filesystems that are >xx% usage.

Then you just need to look into how to send emails from the command line.
Old 02-14-2013, 05:20 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.3
Posts: 17,548

Rep: Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423
What he said

If you bookmark/read these and take it slowly, it shouldn't be too hard.

If you need to automate it, you can use the cron scheduler
Old 02-14-2013, 08:24 PM   #4
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
You can create a script with help of below commands (just for your rederence), and schedule the same in your system's crontab.
df -h | awk -F" " '{gsub(/\%/,"",$4); if($4>=70) print $0}' > /tmp/fs_status.txt
mailx -s "File system status" < /tmp/fs_status.txt
Old 02-16-2013, 10:02 AM   #5
LQ Newbie
Registered: Mar 2011
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks all

Thanks to everyone for the reply. Now I have an idea how to approach the problem. I will respond with the result.


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
Disk Usage Analyzer reports too much disk space? ler0nldb2 Linux - Newbie 1 09-12-2009 10:27 AM
An extensive discussion of if-then usage for shell scripting? Cyberman Programming 6 03-22-2009 01:33 PM
LXer: Save disk space - use compFUSEd to transparently compress filesystems LXer Syndicated Linux News 0 06-10-2008 03:40 PM
ext2 and ext3 use way more disk space then the other filesystems Necronomicom Linux - General 0 08-15-2004 10:06 PM
101% disk usage on an empty disk tsiuser Linux - Software 3 01-28-2004 06:24 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:15 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