Shell script to sum up the space allocated to filesystems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to sum up the space allocated to filesystems
# 1  
Old 01-26-2016
Shell script to sum up the space allocated to filesystems

Hi ,

I Would like to know the space allocated by adding up all the allocated space to group of filesystems ..

example ,

Code:
df -h|grep /db | awk '{ print $4 }'

---> giving me all the used space on the filesystem but need to know the total used space by adding up all the values

Last edited by Don Cragun; 01-26-2016 at 11:21 PM.. Reason: Add CODE tags.
# 2  
Old 01-26-2016
Assuming that you have more than one filesystem mounted on directories under /db (as in /db/database2, /db/database2, ...), try:
Code:
df /db/* | awk '{ avail += $4 } END {print avail}'

Assuming that you have more than one filesystem mounted on directories with names starting with db (as in /db1, /db2, ...), try:
Code:
df /db* | awk '{ avail += $4 } END {print avail}'

Note that there is no -h on the df invocations. Human readable output is fine if it is being read by a human. It is a nuisance if you're trying to add numbers (some of which are in terabytes, some of which are in gigabytes, some of which are in megabytes, ...).

Note that you can tell df which filesystems to process which makes it run faster since it doesn't have to process filesystems you don't care about and it gets rid of the need for the grep.

In both of the above suggestions, if you want to print the individual df output lines and print the total, change:
Code:
avail += $4

in the above scripts to:
Code:
print $4; avail += $4

if you just want to print the sizes with a total at the end, or to:
Code:
print; avail += $4

if you want to print the entire lines from df followed by the total available space on those filesystems.
# 3  
Old 01-26-2016
Thanks very much!!

I would try it ,however i have other filesystem with archive too which needs to be added apart from db filesystems .i just need the sum of allocated space to filesystems.


I though of using the below


Code:
df -h | egrep 'db|archive'


Let me know any other alternative...
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and code segments.

Last edited by Don Cragun; 01-27-2016 at 12:05 AM.. Reason: Add CODE tags again.
# 4  
Old 01-27-2016
Please show us the output from the command:
Code:
df

and indicate which filesystems you want to include in the total.

And, do you just want the total, or do you want the individual filesystem sizes listed followed by the total?
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find the disk space allocated.

Hello, I need to find the total allocated disk space for the home directory. How can i find that in unix?(in GB). Thanks. (4 Replies)
Discussion started by: kailash19
4 Replies

2. Solaris

How much portion of RAM is allocated to Swap space?

How swap is getting 12GB as its size as per the below output: Filesystem size used avail capacity Mounted on /dev/md/dsk/d0 7.9G 2.1G 5.7G 27% / /devices 0K 0K 0K 0% /devices ctfs 0K 0K 0K 0% /system/contract proc 0K 0K 0K 0% /proc mnttab 0K 0K 0K 0% /etc/mnttab swap 12G 1.2M 12G 1%... (3 Replies)
Discussion started by: ramnagaraj
3 Replies

3. Shell Programming and Scripting

Help with variables for filesystems allocated

Hi all, I am interning in a unix department and am very new to programming. I am supposed to write a script that counts the amount of filesystems a server has allocated, and the amount free. This is what I was given to start with: #!/bin/ksh df -m | grep -v ":"|grep -v Free|grep -v "/proc"|... (6 Replies)
Discussion started by: compan023
6 Replies

4. Solaris

Increasing allocated space to a mount - possible?

Hey guys, I am somewhat new to Solaris - and very new when it comes to mounts. My problem is that when I installed Solaris, I allocated way too little diskspace to my / mount (it first became obvious now, however, because of new needs). bash-3.00# df -h Filesystem size ... (25 Replies)
Discussion started by: brightstorm
25 Replies

5. HP-UX

Problem running out of space by copying files to identical filesystems

I am trying to copy a filesystem from one server to another using rsync over the WAN. As far as I can tell, the two filesystems are identical but for some reason I cannot copy the last file because I keep running out of space. SERVER 1: mkfs -m <lvol> mkfs -F vxfs -o... (1 Reply)
Discussion started by: keelba
1 Replies

6. Solaris

Can be changeed the allocated space

i am working with solaris 9 and my disk usages are # df -k Filesystem kbytes used avail capacity Mounted on /dev/dsk/c0t0d0s0 2148263 1902721 202577 91% / /proc 0 0 0 0% /proc mnttab 0 0 0 ... (3 Replies)
Discussion started by: smartgupta
3 Replies

7. UNIX for Dummies Questions & Answers

df+du=Total space allocated(for a file system)

Hi All, Will df+du=Total space allocted for a file system?? Is the above correct. Please correct me If iam wrong. In one my programs the above is not happening. Please help me out. Many thanks. Regards, Manas (2 Replies)
Discussion started by: manas6
2 Replies

8. UNIX for Dummies Questions & Answers

Swap space used greater than allocated using top

Hi there, When I run top on my machine it says I have 497M swap space in use, and 380M swap space free, but I have only allocated 512M swap space to the machine!!!! Does anyone know how swap used is calculated in the top command? Thanks... (1 Reply)
Discussion started by: chorgan
1 Replies
Login or Register to Ask a Question