Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17975737
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类:

2008-05-03 10:57:01

作者 : Nicky Wang
备注 : 新手,也许有些写的冗长,望指点!
用途 : 检查使用情况
适用 :
功能 : 在config中设定允许的最大百分比,每天增长最大百分比,;如果有超出设定范围的,则会发mail通知相关人员。
前提 : 邮件服务器地址
=============DiskCheck.csh=================
#!/bin/csh
# ------------------------------------
# Check Disk Space and Send Mail to User
#
# ------------------------------------

# ----Declare variables--------------
set progpath = $0
set sourcedir = $progpath:h
set a = `grep "server:" $sourcedir/DiskCheck.config`
set servername = $a[2]
set a = `grep "maxused:" $sourcedir/DiskCheck.config`
set maxused = $a[2]
set b = `grep "maxincrease:" $sourcedir/DiskCheck.config`
set maxincrs = $b[2]
set mails = `grep "mailto:" $sourcedir/DiskCheck.config`
set b = `grep "mailday:" $sourcedir/DiskCheck.config`
set mailday = $b[2]
set UsedFlag = "F"
set IncrsFlag = "F"

#-----Check OS and write data to log file-------
set mOS = `uname`
if ( $mOS == "HP-UX" ) then
bdf > $sourcedir/DiskCheck.log.new
else
df -k > $sourcedir/DiskCheck.log.new
endif

#---Check if Current day have to send mail------
set a = `date`
if ( $a[1] == $mailday ) then
foreach mailto($mails)
#----check if $mailto is a validate mail address----
set flag = `echo $mailto|awk -F@ '{print NF-1}'`
if !( $flag == "0" ) then
mailx -s $servername" Disk Usage Ratio Check (weekly)" $mailto < $sourw
endif
end
endif

#--set allused = `awk '{print $5}' $sourcedir/DiskCheck.log.new`
set allused = `awk -F"%" '{print $1}' $sourcedir/DiskCheck.log.new | awk '{prin`
#-----Check maxused disk space and send mail------
set index = 2
while ( $index <= $#allused )
#----check max value----
if ( $allused[$index] >= $maxused ) then
set UsedFlag = "T"
endif
@ index = $index + 1
end

if ( $UsedFlag == "T" ) then
foreach mailto($mails)
#----check if $mailto is a validate mail address----
set flag = `echo $mailto|awk -F@ '{print NF-1}'`
if !( $flag == "0" ) then
mailx -s $servername" Disk Usage Ratio Alarm Mail" $mailto < $sourcedirw
endif
end
endif

#------Check Increasing speed and send mail-----
#-----Check old log exist-----------------------
if ( -e $sourcedir/DiskCheck.log ) then
set oldused = `awk -F"%" '{print $1}' $sourcedir/DiskCheck.log | awk '{print`
set index = 2
while ( $index <= $#oldused )
#-----Check increasing speed-----
@ incrs = $allused[$index] - $oldused[$index]
if ( $incrs >= $maxincrs ) then
set IncrsFlag = "T"
endif
@ index = $index + 1
end

if ( $IncrsFlag == "T" ) then
foreach mailto($mails)
#----check if $mailto is a validate mail address----
set flag = `echo $mailto|awk -F@ '{print NF-1}'`
if !( $flag == "0" ) then
mailx -s $servername" Disk Usage Ratio Increasing Alarm Mail" $mailw
endif
end
endif
endif
#------replace old log with the new one-----
\mv $sourcedir/DiskCheck.log.new $sourcedir/DiskCheck.log


================DiskCheck.config================
#-------------------------
#please set the check item
#-------------------------

#----set the server name----
server: C01BOD05
#----set the maximum used radio (%) of disk space you allowed
maxused: 80

#----set the maximun daily increasing radio (%) speed you allowed
maxincrease: 5

#----set mail address to Inform
mailto:,

#----set whick day to send mail every week
mailday: Thu
===============================================
阅读(2212) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~