免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1294 | 回复: 8
打印 上一主题 下一主题

监视文件系统 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-08-24 11:07 |只看该作者 |倒序浏览
有什么问题,请指点
#!/usr/bin/ksh
#
#SCRIPT:fs_mon_aix.ksh
#
#AUTHOR:gaob
#
#DATE:15-08-2005
#
#PLATFORM:aix
#
#PURPOSE:监视文件系统
#
#REV
#
#set -n
#set -x
####define files and variables here ####
FSMAX="85"                                #文件使用的上限85%
WORKEFILE="/home/gaob/df.work"                #保存df的数据
>$WORKFILE                                #文件初始化,文件清空
OUTFILE="/home/gaob/df.outfile"                #保存超过85%的数据
>$OUTFILE                                #文件初始化,文件清空
THISHOST=`hostname`                        #显示主机名
####start of main###################
df -k |tail +2|egrep -v '/dev/cd[0-9] | /proc'  \
      |awk '{print $1,$4,$7}'  >$WORKFILE        #查出数据并且保存在worfile中
####比较数据######################
while read FSDEVICE FSVALUE FSMOUNT
do
        FSVALUE=$(echo $FSVALUE |sed s/\%//g)       
        typeset -i FSVALUE
        if [$FSVALUE -gt FSMAX]       
        then
        echo "$FSDEVICE mounted on $ FSMOUNT IS ${FSVALUE}%"
                >>$OUTFILE
        fi
done < $WORKFILE
if[[-s $OUTFILE]]
then
        echo "\nfull filesystem(s) on $THISHOST\n"
        cat $OUTFILE
        print
fi

论坛徽章:
0
2 [报告]
发表于 2005-08-24 11:37 |只看该作者

监视文件系统

[$FSVALUE -gt FSMAX]   [ 和表达式之间因该有空格,不知道是不是你的笔误 应该是 [ $FSVALUE -gt FSMAX ]

论坛徽章:
0
3 [报告]
发表于 2005-08-24 11:44 |只看该作者

监视文件系统

[与[[混用,有啥好处啊!

论坛徽章:
0
4 [报告]
发表于 2005-08-24 15:13 |只看该作者

监视文件系统

while read FSDEVICE FSVALUE FSMOUNT
上面的变量是怎么定义的

论坛徽章:
0
5 [报告]
发表于 2005-08-24 15:58 |只看该作者

监视文件系统

while read FSDEVICE FSVALUE FSMOUNT
上面的变量是怎么定义的

论坛徽章:
0
6 [报告]
发表于 2005-08-24 16:01 |只看该作者

监视文件系统

原帖由 "spiceboy123456" 发表:
while read FSDEVICE FSVALUE FSMOUNT
上面的变量是怎么定义的

这里的三个变量应该是你后面的done<file中的file文件中三个域分别赋予这三个变量名吧!

论坛徽章:
0
7 [报告]
发表于 2005-08-24 18:27 |只看该作者

监视文件系统

df -k |tail +2|egrep -v '/dev/cd[0-9] | /proc'  \
     |awk '{print $1,$4,$7}'  >$WORKFILE

这句话把df -k的输出结果取第1、4、7列保存在$WORKFILE里,然后read后三个变量分别去读

论坛徽章:
0
8 [报告]
发表于 2005-08-24 18:53 |只看该作者

监视文件系统

这不就是学习bash里面的么

论坛徽章:
0
9 [报告]
发表于 2005-08-24 19:38 |只看该作者

监视文件系统

original version of the script fs_mon_AIX.ksh, written by Randy Michael, author of the Mastering Unix Shell Scripting, tested without problem .

  1. #!/usr/bin/ksh
  2. #
  3. # SCRIPT: fs_mon_AIX.ksh
  4. # AUTHOR: Randy Michael
  5. # DATE: 08-22-2001
  6. # REV: 1.1.P
  7. # PURPOSE: This script is used to monitor for full filesystems,
  8. #     which is defined as "exceeding" the FSMAX value.
  9. #     A message is displayed for all "full" filesystems.
  10. #
  11. # PLATFORM: AIX
  12. #
  13. # REV LIST:
  14. #
  15. # set -n # Uncomment to check syntax without any execution
  16. # set -x # Uncomment to debug this script
  17. #
  18. ##### DEFINE FILES AND VARIABLES HERE ####  

  19. WORKFILE="/tmp/df.work"      # Holds filesystem data
  20. >$WORKFILE                           # Initialize to empty
  21. OUTFILE="/tmp/df.outfile"      # Output display file
  22. >$OUTFILE                                   # Initialize to empty
  23. THISHOST=`hostname`               # Hostname of this machine
  24. FSMAX="85"                           # Max. FS percentage value

  25. ######## START OF MAIN #############

  26. # Get the data of interest by stripping out /dev/cd#,
  27. # /proc rows and keeping columns 1, 4 and 7

  28. df -k | tail +2 | egrep -v '/dev/cd[0-9]|/proc' \
  29.    | awk '{print $1, $4, $7}' > $WORKFILE

  30. # Loop through each line of the file and compare column 2

  31. while read FSDEVICE FSVALUE FSMOUNT
  32. do
  33.       FSVALUE=$(echo $FSVALUE | sed s/\%//g) # Remove the % sign
  34.       if [ $FSVALUE -gt $FSMAX ]
  35.       then
  36.           echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
  37.                 >> $OUTFILE
  38.       fi
  39. done < $WORKFILE

  40. if [[ -s $OUTFILE ]]
  41. then
  42.       echo "\nFull Filesystem(s) on $THISHOST\n"
  43.       cat $OUTFILE
  44.       print
  45. fi
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP