Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-18-2011, 03:52 PM   #1
Registered: Nov 2002
Location: Rio Rancho, NM
Distribution: RHEL, CentOS & Ubuntu
Posts: 90

Rep: Reputation: 15
Combine 40 different mount points into one bytes free/used number...

We have a program that catalogs to 40 different mount points. The program is fine as long as thier is free space on at least one of the 40 mount points. My boss wants me to come up with a script that will email us daily to know how much overall free space is left. I know I can do a df but I don't know how to combine the 40 mount points into a single disk used/disk free report.

The 40 mount points are /dev/mapper/areaxx, xx being 01 to 40.

Last edited by shelby; 02-18-2011 at 03:54 PM.
Old 02-18-2011, 04:15 PM   #2
Senior Member
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,330

Rep: Reputation: 254Reputation: 254Reputation: 254
How would you do it by hand to get the disk used/disk free space? In the end it could be something like:
df ... | awk ... | mail -s "Disk report" ...
Old 02-18-2011, 04:30 PM   #3
Registered: Mar 2007
Distribution: Debian
Posts: 547

Rep: Reputation: 67
Here is my suggestion for getting the number


let "n = $(df | grep area | wc -l)"
let "sum = 0"
for i in `seq $n`
        let "sum = sum + $(df | grep area | awk '{print $4}' | sed -n ''$i'p')"
echo $sum
Old 02-19-2011, 07:29 AM   #4
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,600

Rep: Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926
@almatic - I hate to be real picky, but would you really use:
let "sum = sum + $(df | grep area | awk '{print $4}' | sed -n ''$i'p')"
Both awk and sed have all that you need to do any of the other steps, it seems pointless to include all 3.

Maybe this example will help:
df | awk '/area/{sum+=$4}END{print sum}'
1 members found this post helpful.
Old 02-19-2011, 04:27 PM   #5
Registered: Mar 2007
Distribution: Debian
Posts: 547

Rep: Reputation: 67
df | awk '/area/{sum+=$4}END{print sum}'
wow, that is very elegant !


awk, shell script

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
[SOLVED] Echo only text after a specific number of bytes genderbender Programming 3 09-01-2010 05:44 AM
play free (World of WarCraft , xBox Live, Live Points, Wii Points, Free Habbo) laraaj Linux - Games 1 02-09-2007 05:50 PM
Monitor eth0, number of bytes passed through?? helptonewbie Linux - Networking 4 09-06-2006 10:49 AM
Combine number and text Ephracis Programming 3 11-17-2004 11:13 AM > Forums > Non-*NIX Forums > Programming

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