zoukankan      html  css  js  c++  java
  • shell脚本监控

    监控磁盘空间

    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
    #此文件里的项目可自定义增减
  • 相关阅读:
    vue跨域代理配置
    vue中引入jquery
    vue中使用特殊字体
    vue中使用mockjs
    vue中使用动态echart图表
    解决win10休眠后无法唤醒
    nvm-windows的安装配置
    黑苹果快捷键
    python基础知识
    如何高效的学习python
  • 原文地址:https://www.cnblogs.com/zhou2019/p/10741045.html
Copyright © 2011-2022 走看看