LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 02-18-2011, 03:52 PM   #1
shelby
Member
 
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
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
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" ...
 
Old 02-18-2011, 04:30 PM   #3
almatic
Member
 
Registered: Mar 2007
Distribution: Debian
Posts: 547

Rep: Reputation: 67
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
 
Old 02-19-2011, 07:29 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,412

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
@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}'
 
1 members found this post helpful.
Old 02-19-2011, 04:27 PM   #5
almatic
Member
 
Registered: Mar 2007
Distribution: Debian
Posts: 547

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


Reply

Tags
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


All times are GMT -5. The time now is 09:01 AM.

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 Google+: linuxquestions
Open Source Consulting | Domain Registration