Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtain value from df

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

A df -k cmd in my HPUX machine gives the output :

/home/etbc01/KISS-EAI-R1 (/dev/VG_tbc/tibco_uat ) : 35510664 total allocated Kb
13786728 free allocated Kb
21723936 used allocated Kb
61 % allocation used

I need to obtain the value "61 %" from the above.. I have a script that obtains the free space.. can anyone please modify it for me ? here goes:

#!/usr/bin/sh

if (test $# -eq 0); then
df -k | awk '/\/home / || /\/opt /{
dir=$1;
getline;
free=$1;
print dir" "free
}'
else
df -k | awk '$1=="/"check {
dir=$1;
getline;
free=$1;
print free;
flag="true";
} END {
if (flag=="false") print -1
}' check="$1" flag="false"
fi
 
/allocation used/ { percent = $1 }

But that probably wont help you much out, How about..

getline; getline; percent = $1 " %"

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
Code:
#!/bin/sh

test $# -eq 0 && check=/home || check=$1

awk -v check="$check" '$1 ~ "/?" check " " {
  seen++
  dir = $1; getline; free = $1; getline; getline; percent = $1
  printf "%s -> %d free(%d)\n", dir, free, percent
} END { if (! seen) { print -1; exit 1 } }'

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top