2013年5月8日 星期三

[系統] 監控HD容量


檔名:/shell/disk.sh

#####################
說明:利用 mount 指令解決 Read-only file system 問題
#####################
#!/bin/sh
ADMIN="xxx@crypto.ee.ncku.edu.tw"
# set alert level 90% is default
ALERT=90
day=`date +"%Y%m%d%H%M"`

df -H | grep -vE '^Filesystem|dev/da0s1a|devfs' | awk '{ print $5 " " $6 }' | while read output;
do
 echo $output
 usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
 partition=$(echo $output | awk '{ print $2 }' )
 if [ $usep -ge $ALERT ]; then
   echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
    mail -s "Alert: Almost out of disk space $usep%" $ADMIN

# clear ops server /var/mail/root file
   if [ $partition=="/usr/testbed/usersvar" ]; then
     mount -o rw  /usr/testbed/usersvar
     cp -p /usr/testbed/usersvar/mail/root /mnt/backup2/ops_var_log_bak/mail/root."$day"
     cat /dev/null > /usr/testbed/usersvar/mail/root
    umount /usr/testbed/usersvar
   fi

# clear boss server /var/log
   if [ $partition=="/var" ]; then
     cp -p /var/log/auth.log /mnt/backup2/boss_var_log_bak/auth.log."$day"
     cat /dev/null > /var/log/auth.log
     cp -p /var/log/maillog /mnt/backup2/boss_var_log_bak/maillog."$day"
     cat /dev/null > /var/log/maillog
   fi
 fi

done

-----------------------------------------------------------------------
修改crontab

#ee /etc/crontab

-----------------------------------------------------------------------
新增底下二行!! 每5分鐘檢查一次
# mointor disk
*/5     *       *       *       *       root    /shell/disk.sh


沒有留言:

張貼留言