LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-29-2009, 03:20 PM   #16
MartenH
Member
 
Registered: Jul 2005
Location: Lund, Sweden
Distribution: Mandriva
Posts: 76

Original Poster
Rep: Reputation: 23

Thanks. Everything is working now. I adjusted the code supplied by admiral to work as desired (including showing for each device). I also end with a slightly adjusted version of the code from Tinkster.

For future reference here is the code:
Code:
#!/bin/sh
#### This script output the amount of space fore each device
#### and two ways of showing the cumulative sum
df -h $line | grep dev | sed 's|/dev/|''|' | awk '{ print $1, $2, $3, $4 }' | sed s/G/''/g > /tmp/drives.txt
exec < /tmp/drives.txt
echo ''
echo -e "Device\tSize\tUsed\tAvail"
while read line
do
let FULLSIZE+=`echo -e $line | awk '{ print $2 }'`
let USEDSIZE+=`echo -e $line | awk '{ print $3 }'`
let AVAILSIZE+=`echo -e $line | awk '{ print $4 }'`
   echo -e $line | awk '{ print $1"\t", $2"\t", $3"\t", $4"\t" }'
done

PERCENT=`awk 'BEGIN{printf("%0.2f", '$USEDSIZE' / '$FULLSIZE' * 100)}'`
PERCENT2=`awk 'BEGIN{printf("%0.2f", '$AVAILSIZE' / '$FULLSIZE' * 100)}'`

echo ''
echo -e "Total:\t$FULLSIZE GB"
echo -e "Used:\t$USEDSIZE ($PERCENT%)"
echo -e "Avail:\t$AVAILSIZE ($PERCENT2%)"

echo ''
df -h | awk 'NR >1 {total+=$2;used+=$3;avail+=$4}END{print "Total: "total" GB";printf("Used: %s GB (%0.5s%)\n", used, used / total * 100);printf("Avail %s GB (%0.5s%)\n", avail, avail / total * 100)}'
 
Old 03-29-2009, 04:04 PM   #17
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I'd just like to point out that using "df -h" makes little sense if you
happen to have a machine that has one partition in the sub-1-G range (as
/boot would commonly be) and make the handling of numbers unnecessarily
complicated with the different magnitudes.


If you're really that keen on the percentages you could slightly modify
the output statement of my END-clause.

I also realised that some file-systems shouldn't be taken in account :}
Code:
df -m | awk 'NR >1 && $1 ~ /\//  {total+=$2;used+=$3;avail+=$4}END{print "Total: "total" MB";printf("Used: %s MB (%0.5s%)\n", used, used / total * 100);printf("Avail %s MB (%0.5s%)\n", avail, avail / total * 100)}'
 
  


Reply


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
How much total Hard Disk Space required to install RHEL AS 5.0 singh_chitranjan Linux - Newbie 3 06-24-2008 01:30 PM
total free space is different than actual sushmi Linux - Newbie 2 06-04-2007 01:48 AM
Nmap help, total newblet from space. zarathaz Linux - Newbie 3 07-19-2005 11:49 PM
format only gives me less than total space ctrl-a Linux - Newbie 4 10-12-2004 04:15 PM
finding total used space by a user in a directory vince_2x Linux - General 1 09-21-2004 06:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration