Filesystems using more than 75% capacity

i need to write a shell script for printing the list of filesystems whose disk utilization is more than 75%...i tried using df -h along with awk but cud'nt make the combination work.....:wall:
when we do df -h then the filesystems which are using more than 75% capacity shud be printed according to the requirement......please help me with it...thanks..:slight_smile:
m working on ksh!!

Try:

df -hP | awk '{x=$5;sub ("%","",x)}x>75'

It looks work too with:

df -h | awk '$5>75'

or similar to bartus solution:

df -h | awk '{sub(/%/,"")}$5>75'

Hope it helps

Regards

Thanks bartus11, i was unaware of the option -P hence came up with below..

df -h | awk '{if(NF==1){x=$0;getline;if(int($4)>75)print x,$0}else if($5>75) print}'

@bartus...it showing the following error
tc95air1(root)# ./script2
df: unknown option: P
Usage: df [-F FSType] [-abeghklntVvZ] [-o FSType-specific_options] [directory | block_device | resource]
awk: syntax error near line 1
awk: illegal statement near line 1

@michael: it's executing and givin the output:) but the o/p seems to be wrong:(
tc95air1(root)# ./script1
Filesystem size used avail capacity Mounted on
/dev/dsk/c1t0d0s6 9.8G 724M 9.0G 8% /unused2

but when i run df -h the following records are shown
tc95air1(root)# df -h
Filesystem size used avail capacity Mounted on
/dev/dsk/c1t0d0s0 20G 8.8G 11G 46% /
/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 2.4G 2.1M 2.4G 1% /etc/svc/volatile
objfs 0K 0K 0K 0% /system/object
sharefs 0K 0K 0K 0% /etc/dfs/sharetab
fd 0K 0K 0K 0% /dev/fd
swap 2.4G 424K 2.4G 1% /tmp
swap 2.4G 40K 2.4G 1% /var/run
/dev/dsk/c1t0d0s5 9.8G 106M 9.6G 2% /unused1
/dev/dsk/c1t0d0s7 16G 1011M 15G 7% /export
/dev/dsk/c1t0d0s6 9.8G 724M 9.0G 8% /unused2
/dev/dsk/c1t0d0s3 9.8G 6.3G 3.4G 65% /voice1
/platform/sun4u-us3/lib/libc_psr/libc_psr_hwcap1.so.1
20G 8.8G 11G 46% /platform/sun4u-us3/lib/libc_psr.so.1
/platform/sun4u-us3/lib/sparcv9/libc_psr/libc_psr_hwcap1.so.1
20G 8.8G 11G 46% /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1

the output doesn't match with the records as it's showing a file system with "8%" usage which is less than 75%:o.....please help me with this..

Could you try the below..

df -h | awk '{if(NF==1){x=$0;getline;if(int($4)>75)print x,$0}else if(int($5)>75) print}'

Which Solaris version are you using?

@bartus:

tc95air1(root)# cat release file
Solaris 10 5/08 s10s_u5wos_10 SPARC
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 24 March 2008

@michael: it's not giving any output now, initially i thot tha no file system must be using more than 75% tht's y, later i changed the threshold to 60%, then too no results...:frowning:

tc95air1(root)# ./script1
tc95air1(root)#

On Solaris df works different when the output is a terminal or a non-terminal

$ df -k
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c1t1d0s0    10327834 7666292 2558264    75%    /
/devices                   0       0       0     0%    /devices
ctfs                       0       0       0     0%    /system/contract
proc                       0       0       0     0%    /proc
mnttab                     0       0       0     0%    /etc/mnttab
swap                 1989320    1400 1987920     1%    /etc/svc/volatile
objfs                      0       0       0     0%    /system/object
/platform/sun4u-us3/lib/libc_psr/libc_psr_hwcap1.so.1
                     10327834 7666292 2558264    75%    /platform/sun4u-us3/lib/libc_psr.so.1
/platform/sun4u-us3/lib/sparcv9/libc_psr/libc_psr_hwcap1.so.1
                     10327834 7666292 2558264    75%    /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1
fd                         0       0       0     0%    /dev/fd
swap                 1987944      24 1987920     1%    /tmp
swap                 1987960      40 1987920     1%    /var/run
/dev/dsk/c1t1d0s4    20549005 12774692 7568823    63%    /project
/dev/dsk/c1t1d0s3    2053605 1696869  295128    86%    /export/home
$ df -k | cat
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c1t1d0s0    10327834 7666292 2558264    75%    /
/devices                   0       0       0     0%    /devices
ctfs                       0       0       0     0%    /system/contract
proc                       0       0       0     0%    /proc
mnttab                     0       0       0     0%    /etc/mnttab
swap                 1989320    1400 1987920     1%    /etc/svc/volatile
objfs                      0       0       0     0%    /system/object
/platform/sun4u-us3/lib/libc_psr/libc_psr_hwcap1.so.1 10327834 7666292 2558264    75%    /platform/sun4u-us3/lib/libc_psr.so.1
/platform/sun4u-us3/lib/sparcv9/libc_psr/libc_psr_hwcap1.so.1 10327834 7666292 2558264    75%    /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1
fd                         0       0       0     0%    /dev/fd
swap                 1987944      24 1987920     1%    /tmp
swap                 1987960      40 1987920     1%    /var/run
/dev/dsk/c1t1d0s4    20549005 12774692 7568823    63%    /project
/dev/dsk/c1t1d0s3    2053605 1696869  295128    86%    /export/home
$

To a terminal, df split long lines into two lines. But when piped to cat, it allowed long lines to stay intact. So we don't need to worry about split lines inside the awk program. Also, on Solaris awk is an antique version. Use nawk to get a "modern" (well, circa 1985) version of awk.

Try this one:

$ cat /etc/release
                       Solaris 10 8/07 s10s_u4wos_12b SPARC
           Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
                        Use is subject to license terms.
                            Assembled 16 August 2007
$ df -h | nawk '{if(int($5)>75) print}'
/dev/dsk/c1t1d0s3      2.0G   1.6G   288M    86%    /export/home
vamain:/vol/vol1/razor_db/workfiles    13T    10T   2.4T    81%    /net/vamain/vol/vol1/razor_db/workfiles
$

Thanx Perderabo....it's workin perfect...:b::slight_smile:

Hey Perderabo,

Can u please add a couple of functionalities to ur command...a mail containing the file system name and usage % should be fired to an ID whenever any file system crosses the threshold set by us..i.e 75%..

what about for HPUX..using bdf