LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Combine 40 different mount points into one bytes free/used number... (http://www.linuxquestions.org/questions/programming-9/combine-40-different-mount-points-into-one-bytes-free-used-number-863606/)

shelby 02-18-2011 03:52 PM

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.

Reuti 02-18-2011 04:15 PM

How would you do it by hand to get the disk used/disk free space? In the end it could be something like:
Code:

df ... | awk ... | mail -s "Disk report" ...

almatic 02-18-2011 04:30 PM

Here is my suggestion for getting the number

Code:

#!/bin/bash

let "n = $(df | grep area | wc -l)"
let "sum = 0"
for i in `seq $n`
do
        let "sum = sum + $(df | grep area | awk '{print $4}' | sed -n ''$i'p')"
done
echo $sum


grail 02-19-2011 07:29 AM

@almatic - I hate to be real picky, but would you really use:
Code:

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:
Code:

df | awk '/area/{sum+=$4}END{print sum}'

almatic 02-19-2011 04:27 PM

Quote:

Code:

df | awk '/area/{sum+=$4}END{print sum}'

wow, that is very elegant !


All times are GMT -5. The time now is 12:25 AM.