周末写了个 monitor filesystem shell ( crontab 定时监控)

来源:互联网 发布:淘宝达人个人简介模版 编辑:程序博客网 时间:2024/06/06 18:41

现在公司的 oracle 文件的 归档filesystem 下太大了,而且要是录用达到100% oracle 的用户是connect 不上去的,于是决定 写个监控的shell:

 

思想: 归档的日志有大有小,当filesystem 在20% 一下就可以认为正常,不要删除,否则就要delete old files.

 

1:好下面来看以下shell: (是放在/tmp/test/monitor.sh)

 

#! /bin/ksh

 

# Function: This shell is to monitor the filesystem.

# Date: Dev 05 2010 sunny Sunday

 

# step1 To to check the filesytem, if it more than 20%,then delete the old files, otherwise to do nothing.

 

df -g > checkfile

grep '/dev/arch' checkfile > ch01

awk '{$print $4}'  ch01 > ch02

ch03=ch02

ch04 = `cat $ch03`

if [ "$ch04" -ge 20 ]; then

 continue

else

  echo "The file system is okay now ,please contunie to work!  ^_^ "

fi

 

#step2 : if the filesystem usage more than 20%, delete the old files, keep the latest 10 files.

 

Dir=/root/temp/data

cd $Dir

ls -lt | awk '{if(NR>11) {print "rm " $9}}' | sh

# step3 check the status:

if [ $? == 0 ]; then

  echo " The filesystem is okay now, please continue to work !"

else

  echo " Please double check the filesytem! "

fi

 

-----------------------

 

2:利用crontab 来定义shell 的运行规律:

写个frequently shell: fre.sh 放在/tmp/test

(每两小时执行一次)

#cat fre.sh

0 */2 * * * /tmp/test/monitor.sh

 

3: 在aix 系统中定制这个fre.sh

#crontab /tmp/test/fre.sh

 

看了上面的shell ,大家有啥感想呢? shell 是为了更好的工作,为工作所用。呵呵,下面我有个想法,就是把这个监控报告定时发送到我的outlook 邮箱。make monitor easy!

原创粉丝点击