- 论坛徽章:
- 1
|
本程序由我亲自设计,可以以下面的格式来显示磁盘的使用情况。并且在字符终端下测试通过
[root@mospapp11 bin]# dfspace
**********************************************************************
dfspace script(v1.0) ,author: xingzhenhua ,date:2006-01-15
**********************************************************************
/: Disk space: 5.52 GB of 11.71 GB available (47.18%)
/boot: Disk space: 97.33 MB of 106.32 MB available (91.55%)
/home: Disk space: 485.67 MB of 493.75 MB available (98.36%)
/log: Disk space: 15.31 GB of 29.25 GB available (52.34%)
/usr: Disk space: 12.56 GB of 19.51 GB available (64.38%)
/var: Disk space: 11.42 GB of 12.68 GB available (90.07%)
*** Total Disk Space: 45.40 GB of 73.76 GB available (61.56%).
************************************************************** (disk capability)
************************ (data)
显示出每个磁盘分片的空间状况,以及整个磁盘的利用率,并以*来直观的表示
本程序主要用awk编写,试用于各种平台
测试平台包括SUN OS,FreeBSD,Linux-Redhat,unixware,SCO 等
程序如下,直接运行即可
#!/bin/sh
export LANG=en_US #redhat-linux
while getopts -- option
do
case "$option"
in
\?) echo "usage: dfspace [ filesys ] ..."
exit 1;;
esac
done
echo "**********************************************************************"
echo "dfspace script(v1.0) ,author: xingzhenhua ,date:2006-01-15"
echo "**********************************************************************"
echo ""
# get free and allocated space.
#/bin/df -k $* | nawk ' # sun os
/bin/df -k $* | awk '
BEGIN {FS=":"; cc=1000/1024}
{
split($1,sys1," "); FSYS = sys1[1]
FSYSM=sys1[6]
if (FSYS ~ /^Filesystem/ ) next;
# if (FSYS !~ /^\/proc/ && FSYS !~ /^\/dev\/fd/ && FSYS !~ /^\/system\/processor/) # unixware
# if (FSYS ~ /^fd/ || FSYS ~ /^\/vol/) next; # sunos
if (FSYS ~ /^none/ ) next; # redhat-linux
alloc=sys1[2]
free=sys1[2]-sys1[3]
if (alloc == 0) alloc = 1; # avoid division by zero
TFREE = free / 1000 * cc
TFREE1 = free / 1000 * cc
TALLOC= alloc / 1000 * cc
TALLOC1=alloc / 1000 * cc
PCT=free * 100 / alloc
if (TFREE < 0) TFREE=0
if (TALLOC < 0) TALLOC=0
if (TFREE > 1000) {TFREE=TFREE/1000; cfree="GB"}
else cfree="MB"
if (TALLOC > 1000) {TALLOC=TALLOC/1000; calloc="GB"}
else calloc="MB"
printf ("%s: Disk space: %#7.2f %s of %#7.2f %s available (%#5.2f%%)\n", FSYSM, TFREE,cfree, TALLOC,calloc, PCT)
Cumfree += TFREE1; Cumalloc += TALLOC1;
}
END {
if (Cumfree > 1000) {Cumfree=Cumfree/1000; ccom="GB"}
else ccom="MB"
if (Cumalloc > 1000) {Cumalloc =Cumalloc /1000; ccalc="GB"}
else ccalc="MB"
if (Cumalloc > 0) {
CumPct=Cumfree * 100 / Cumalloc
CumP=Cumfree/Cumalloc
printf ("\n*** Total Disk Space: %#7.2f %s of %#7.2f %s available (%#5.2f%%).\n", Cumfree,ccom, Cumalloc,ccalc, CumPct)
r0=CumP*62
for (i=0;i<62;i++) { printf("*")}
printf " (disk capability)\n"
for (i=0;i<62-r0;i++) { printf("*")}
printf " (data)\n"
}
}'
# end of disk space calculation.
[ 本帖最后由 xzh2002 于 2006-1-16 15:01 编辑 ] |
评分
-
查看全部评分
|