首页 > 系统服务 > 详细

shell脚本监控

时间:2019-04-20 15:38:46      阅读:138      评论:0      收藏:0      [点我收藏+]

监控磁盘空间

vim check_disk.sh

#!/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
#此文件里的项目可自定义增减

 

shell脚本监控

原文:https://www.cnblogs.com/zhou2019/p/10741045.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!