How do i find free space in my unix?

Hello, I wanted to calculate free space in my unix file system. Here is my direction. I can use df -h command to get the below output.

Filesystem            Size  Used Avail Use% Mounted on
===================================================

/dev/vx/dsk/edcdg/data01vol
                       59G   51G  7.2G  88% /data01
/dev/vx/dsk/edcdg/data02vol
                       59G   52G  6.9G  89% /data02
/dev/vx/dsk/edcdg/data03vol
                       59G   52G  6.7G  89% /data03
/dev/vx/dsk/edcdg/data04vol
                       59G   51G  7.2G  88% /data04
/dev/vx/dsk/edcdg/data05vol
                       59G   49G  9.8G  84% /data05
/dev/vx/dsk/edcdg/data06vol
                       59G   50G  8.9G  85% /data06
/dev/vx/dsk/edcdg/data07vol
                       59G   53G  6.1G  90% /data07
/dev/vx/dsk/edcdg/data08vol
                       59G   52G  6.8G  89% /data08
/dev/vx/dsk/archdg/arch01vol
                       59G  489M   55G   1% /dbArch
/dev/vx/dsk/workdg/work01vol
                      176G   40G  128G  24% /work
/dev/vx/dsk/orasysdg/orasysvol1
                       51G   33G   18G  65% /orasys
/dev/vx/dsk/undodg/undovol1
                       51G  8.1G   41G  17% /undo
/dev/vx/dsk/redodg/redovol1
                       21G  820M   19G   5% /redo01
/dev/vx/dsk/redodg/redovol2
                       21G  820M   19G   5% /redo02
/dev/vx/dsk/redodg/redovol3
                       21G  820M   19G   5% /redo03

===============================================

In each file system, in the AVAIL column, i need to minus 10% and find the grand total. That will be the free space in my server..

How do i do this? I thought of moving this whole output to excel file and deduct 10% from Avail column. But i am not able to move the unix output to excel with correct format.

$ df -h | awk 'NF == 5 {T+=$3} END {print "Total: " T ".  90% of that is " T*.9}' 
Total: 358.6.  90% of that is 322.74

You are the Man!!!

---------- Post updated at 12:36 PM ---------- Previous update was at 11:42 AM ----------

Your script looks good for linux. I have sun OS server. It is not working correctly for SUN OS machine. The AWK script should behave same way in all unix machine. But somehow not...

xmydll002*/export/home/oracle
>uname
SunOS

xmydll002*/export/home/oracle
>df -h
Filesystem             size   used  avail capacity  Mounted on
/dev/md/dsk/d0         103G    27G    76G    26%    /
/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                    38G   1.1M    38G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
sharefs                  0K     0K     0K     0%    /etc/dfs/sharetab
/platform/sun4u-us3/lib/libc_psr/libc_psr_hwcap1.so.1
                       103G    27G    76G    26%    /platform/sun4u-us3/lib/libc_psr.so.1
/platform/sun4u-us3/lib/sparcv9/libc_psr/libc_psr_hwcap1.so.1
                       103G    27G    76G    26%    /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1
fd                       0K     0K     0K     0%    /dev/fd
swap                   2.0G   2.6M   2.0G     1%    /tmp
swap                    38G    48K    38G     1%    /var/run
swap                    38G     0K    38G     0%    /dev/vx/dmp
swap                    38G     0K    38G     0%    /dev/vx/rdmp
/dev/vx/dsk/xyd900/vol003
                        60G    52G   7.6G    88%    /data01
/dev/vx/dsk/xyd900/vol004
                        60G    53G   6.7G    89%    /data02
/dev/vx/dsk/xyd900/vol014
                        60G    53G   6.2G    90%    /data12
/dev/vx/dsk/xyd900/vol011
                        60G    53G   6.5G    90%    /data09
/dev/vx/dsk/xyd900/vol009

xmydll002*/export/home/oracle

xmydll002*/export/home/oracle
>df -h | grep vol0 | awk 'NF == 5 {T+=$3} END {print "Total: " T ".  90% of that is " T*.9}'
Total: .  90% of that is 0

xmydll002*/export/home/oracle
>

Try replacing awk with gawk for SunOS.

Dnbert, gawk is not accepting. it accepts only awk, nawk. It is not giving correct result if we use awk, nawk.

uxydal9878*/export/home/oracle
>uname -a
SunOS uxydal9878 5.10 Generic_138888-03 sun4u sparc SUNW,Sun-Fire-V890

uxydal9878*/export/home/oracle
>df -h | nawk 'NF == 5 {T+=$3} END {print "Total: " T ". 90% of that is " T*.9}'
Total: . 90% of that is 0

uxydal9878*/export/home/oracle
>df -h | awk 'NF == 5 {T+=$3} END {print "Total: " T ". 90% of that is " T*.9}'
Total: . 90% of that is 0

uxydal9878*/export/home/oracle
>df -h | gawk 'NF == 5 {T+=$3} END {print "Total: " T ". 90% of that is " T*.9}'
-bash: gawk: command not found

uxydal9878*/export/home/oracle
>

I should have read your entire snippet. Haha, sorry.

Try something like this:

df |grep -v Ava| cut -c 43-52 | awk 'BEGIN {total=0} {total += $1} {total * .9} END {print total}'

I haven't tested this so be weary, especially with that cut. That was just a guesstimation.

Thanks.. I might need to learn more about AWK programming to get this done. But the beauty is, the same code works in linux and does not work in sunos...

df -h | awk 'NF == 5 {T+=$3} END {print "Total: " T ". 90% of that is " T*.9}'

GNU awk is used in 99% of all Linux and has some extended features the lack of which can turn simple solutions very ugly. Much like how GNU date's -d option is so convenient; "how do I subtract dates in shell?" "convert to seconds with GNU date and subtract" "I don't have GNU date" "Then try this 4-page shell script but not on leap years!"

Hi.

You can get the awk to behave the same way on all machines. The problem is that df doesn't!

On Solaris 10:

# df -k | awk 'NR > 1 {T+=$(NF-2)} END {print T/1024/1024 " GB.  90% of that is " T/1024/1024*.9 " GB"}'
32.4194 GB.  90% of that is 29.1775 GB

Thanks Corona688, Thanks scott. Your response Helps.