1833708 Members
2538 Online
110063 Solutions
New Discussion

awk question

 
SOLVED
Go to solution
Igor Sovin
Super Advisor

awk question

Hi!
How to get free space left on file system /var/opt/ignite/recovery/archives
from the following output?

root@lev />bdf
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 1048576 318056 724872 30% /
/dev/vg00/lvol1 1081344 178744 895592 17% /stand
/dev/vg00/lvol10 20480000 9382744 11010664 46% /var
/dev/vg01/ignite 116686848 101012876 14694408 87% /var/opt/ignite/recovery/archives
/dev/vg00/lvol9 3768320 2676568 1083264 71% /usr
/dev/vg00/lvol6 1048576 140544 900976 13% /tmp
/dev/vg00/lvol8 20480000 2682088 17658928 13% /opt
/dev/vg00/lvol7 1048576 23512 1021288 2% /home
/dev/vg00/lvol5 10256384 3250963 6567630 33% /depot
/dev/vg00/lvol4 2097152 1888853 195328 91% /.audit
anny:/ignite 143327232 51600 134320912 0% /ignite_Old
13 REPLIES 13
Arunvijai_4
Honored Contributor
Solution

Re: awk question

Hi Igor,

You can try this,

# bdf /dev/vg01/ignite | awk '{a+=$4} END {printf "%d\n",a}'

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Chauhan Amit
Respected Contributor

Re: awk question

Try following command :

bdf |grep -i /var/opt/ignite/recovery/archives |awk '{print $4}'

output will be in KB

-Amit
If you are not a part of solution , then you are a part of problem
Igor Sovin
Super Advisor

Re: awk question

Thank you guys!
inventsekar_1
Respected Contributor

Re: awk question

hi igor,
this u can use and get the bdf result in mb.
============================================================
#!/usr/bin/ksh

echo "Filesystem Mbytes used avail %used Mounted on"

bdf | grep -v Filesystem | awk '{ printf("%s %10d %10d %10d %4s %s\n",$1,$2/1024,$3/1024,$4/1024,$5,$6)}'
============================================================




Be Tomorrow, Today.
rariasn
Honored Contributor

Re: awk question

Hi!

# df -b

rgs,

ran
rariasn
Honored Contributor

Re: awk question

Sorry,

df -b|grep -i ignite
/var/opt/ignite/recovery/archives (/dev/vgvarignite/lvrecovery) : 7676261 Kbytes free

rgs,
ran
Kenan Erdey
Honored Contributor

Re: awk question

hi;

without awk:
bdf | head -5| tail -1 | tr -s ' ' | cut -f4 -d' '
Computers have lots of memory but no imagination
Bill Hassell
Honored Contributor

Re: awk question

Wow, I'm surprised that no one suggested the simplest method:

bdf /var/opt/ignite/recovery/archives

No grep, no awk, nothing but bdf. You could pipe the second line from bdf into read and extract just the free space:

bdf /var/opt/ignite/recovery/archives | while read HEADER REPLY
do
if [ "$HEADER" = "Filesystem" ]
then
read DEV CAP USED FREE PCT FS
MEGSFREE=$(echo $FREE | awk '{print int($1/1024+.5)}')
echo "$FS has $FREE Kbytes ($MEGSFREE megs) free space"
fi
done

The above shows both Kb and megs.


Bill Hassell, sysadmin
Peter Nikitka
Honored Contributor

Re: awk question

Hi,

I think Igors problem was the 2line-output of the bdf command for long device names; Bills response will handle that.

To get a bdf-like 1line-output for further processing in all cases, I suggest (untested):

bdf | awk 'NR>1 {if(ok) print line; ok=0;line=$0}
NF==1 {line=line" "$0;ok=1}
NF>5 {ok=1}
END {print line}'

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
H.Merijn Brand (procura
Honored Contributor

Re: awk question

Why does no-one promote 'di'?
http://www.gentoo.com/di/
Heh, I didn't know the reference to binary packages from there would be to *my* site. Bet I will have to make 4.5 available soon now, won't I ...

a5:/u/usr/merijn 109 > di -?
di: illegal option -- ?
di ver 4.1 Default Format: smbuvpT
Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]
[-I include-fstyp-list] [file [...]]
-a : print all mounted devices
-d x : size to print blocks in (512 - POSIX, k - kbytes,
m - megabytes, g - gigabytes, t - terabytes, h - human readable).
-f x : use format string
-I x : include only file system types in
-x x : exclude file system types in
-l : display local filesystems only
-n : don't print header
-t : print totals
Format string values:
m - mount point M - mount point, full length
b - total kbytes B - kbytes available for use
u - used kbytes c - calculated kbytes in use
f - kbytes free v - kbytes available
p - percentage not avail. for use 1 - percentage used
2 - percentage of user-available space in use.
i - total file slots (i-nodes) U - used file slots
F - free file slots P - percentage file slots used
s - filesystem name S - filesystem name, full length
t - disk partition type T - partition type, full length
See manual page for more options.
Exit 1
a5:/u/usr/merijn 110 > di -ff /tmp
Free
499.2
a5:/u/usr/merijn 111 > di -n -ff /tmp
499.2
a5:/u/usr/merijn 112 > di -n -ff -dm /tmp
499.2
a5:/u/usr/merijn 113 > di -n -ff -dk /tmp
511221
a5:/u/usr/merijn 114 >

http://mirrors.develooper.com/hpux/di-4.1-10.20.sd.bz
http://mirrors.develooper.com/hpux/di-4.1-11.00.sd.bz
http://mirrors.develooper.com/hpux/di-4.1-11.11.sd.bz
http://mirrors.develooper.com/hpux/di-4.1-11.23.sd.bz
http://mirrors.develooper.com/hpux/di-4.4-11.23.sd.bz

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: awk question

OK, all 4.5 ports are now up

a5:/u/usr/merijn 101 > di -?
di: illegal option -- ?
di ver 4.5 Default Format: smbuvpT
Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]
[-I include-fstyp-list] [file [...]]
-a : print all mounted devices
-d x : size to print blocks in (512 - POSIX, k - kbytes,
m - megabytes, g - gigabytes, t - terabytes, h - human readable).
-f x : use format string
-I x : include only file system types in
-x x : exclude file system types in
-l : display local filesystems only
-n : don't print header
-t : print totals
Format string values:
m - mount point M - mount point, full length
b - total kbytes B - kbytes available for use
u - used kbytes c - calculated kbytes in use
f - kbytes free v - kbytes available
p - percentage not avail. for use 1 - percentage used
2 - percentage of user-available space in use.
i - total file slots (i-nodes) U - used file slots
F - free file slots P - percentage file slots used
s - filesystem name S - filesystem name, full length
t - disk partition type T - partition type, full length
See manual page for more options.

http://www.cmve.net/~mbrand/di-4.5-10.20.sd.bz
http://www.cmve.net/~mbrand/di-4.5-11.00.sd.bz
http://www.cmve.net/~mbrand/di-4.5-11.11.sd.bz
http://www.cmve.net/~mbrand/di-4.5-11.23.sd.bz

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Arturo Galbiati
Esteemed Contributor

Re: awk question

Hi Igor,
bdf var/opt/ignite/recovery/archives|\
awk 'BEGIN {printf "%-16s %14s %14s %14s %8s %s\n","Filesystem","kbytes","used","avail","%used","Mounted on"}
!/Filesystem/ {KBYTES=KBYTES+$2; USED=USED+$3; AVAIL=AVAIL+$4; NBR=++NBR}
END {printf "%-16s %14s %14s %14s %7s \n","================","===========","==========","==========","===="
printf "%-16s %14d %s %11d %s %11d %s %4d% \n","total",KBYTES,"Kb",USED,"Kb",AVAIL,"Kb",USED*100/KBYTES
printf "%-16s %14d %s %11d %s %11d %s \n"," ",KBYTES/1024,"Mb",USED/1024,"Mb",AVAIL/1024,"Mb"
printf "%-16s %14d %s %11d %s %11d %s \n"," ",KBYTES/1048576,"Gb",USED/1048576,"Gb",AVAIL/1048576,"Gb"}

HTH,
Art
Bill Hassell
Honored Contributor

Re: awk question

Peter pointed out that I did not test for a long line in a bdf listing. There is an inserted test for a null size and a second read to get the second line. This is common a problem with NFS filesystems (long source names):

bdf /house | while read HEADER REPLY
do
if [ "$HEADER" = "Filesystem" ]
then
read DEV CAP USED FREE PCT FS
[[ "$CAP" = "" ]] && read CAP USED FREE PCT FS
MEGSFREE=$(echo $FREE | awk '{print int($1/1024+.5)}')
echo "$FS has $FREE Kbytes ($MEGSFREE megs) free space"
fi
done


Bill Hassell, sysadmin