#!/bin/bash # test common.
#warn=$1 #err=$2 #mount=$3
check_val() { /usr/bin/expr $1 + 100 > /dev/null 2>&1 return=$(echo $?)
if [[ ${return} -ne 0 ]] then echo "please input number." exit 1 fi }
conf="./check_disk.conf"
if [[ ! -f ${conf} ]] then echo "config file is not exists." exit 1 fi
while read line do mount=${line%%=*} monitor=${line##*=} warn=${monitor%%,*} err=${monitor##*,}
check_val $warn check_val $err #echo "mount: ${mount}; warrn: ${warrn}; err: ${err}"
#qu ci pan kong jian. value=$(df -h | awk '{if($NF == "'"$line"'") print substr($5,1,length($5)-1)}') if [[ $value -gt ${warn} ]] then echo "${mount}: disk is full." d=$(date +"%s") cp /root/shell/log/messages /root/shell/log-bak/messages.${d} cat /dev/null > /root/shell/log/messages elif [[ $value -gt ${err} ]] then echo "${mount}: disk is crital." else echo "${mount}: It's normal." fi done<${conf} vim check_disk.conf /=80,90 /boot=80,90 /dev=80,90 #此文件里的项目可自定义增减