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!

Monitor free disk space

Status
Not open for further replies.

ninggolpindo

IS-IT--Management
Dec 2, 2003
6
US
Hello. From what I read in the threads in this forum, I can use df -k to check free disk space. It will give me the usage per file system. How will I be able to know the free space for the entire server? I need to know this to determine if I need to order/extend more space.

Thanks.
 
Try this :

df -k | awk '
NR>1 {
total += $2;
free += $3;
}
END {
printf "Total space : %10d K\n", total;
printf "Free space : %10d K\n", free;
printf "%%Free space : %10d %\n", free * 100 / total;
} '



Jean Pierre.
 
Sorry, typing error :

printf "%%Free space : %10d %%\n", free * 100 / total;

Jean Pierre.
 
This is what I use (SCO, may or may not work with your *nix flavor):
#!/usr/bin/awk -f
# cmd/df.awk Disk Free
BEGIN {
cmd="sync;LANG=C df -tk";fmt="%-28s %-23s%9s %9s %7s\n"
printf fmt,"Répertoire","FileSystem","Total(Mb)","Libre","Occup."
trt=sprintf(fmt,"----------","----------","---------","---------","------")
printf trt
fmt="%-28s %-23s%#9.2f %#9.2f %6.2f%%\n"
while((cmd|getline)==1){
if(substr($1,1,1)=="/"){
mountDir=$1
mountDev=substr($2,1,1)=="(" ? substr($2,2) : $2
sub(/[) \t]*:$/,"",mountDev)
Free=(substr($3,1,1)==")" ? $4 : $3)/1000
} else if($0~/otal/){
Tot=($1~/otal/ ? $2 : $1)/1000
if(Tot){
printf fmt,mountDir,mountDev,Tot,Free,100*(Tot-Free)/Tot
tTot+=Tot;tFree+=Free;Nb++
}}
}; close(cmd)
exit
}
END {
if(tTot && Nb>1){
printf trt""fmt,"Recap","Tous",tTot,tFree,100*(tTot-tFree)/tTot
}}

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top