LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
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
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
@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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:11 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration