shell指令碼監控分區使用率,並發郵件警示

來源:互聯網
上載者:User

標籤:監控   shell   

最近線上一個分區使用過快,nagios並沒有開啟對分區使用率的監控,抽了幾分鐘臨時寫了個指令碼先用著。用法比較簡單,直接上代碼:

註:代碼中用到的sendEmail指令碼是perl開發的一個發郵件程式,可以網上找到該指令碼或者使用其他發郵件指令碼

#!/bin/bash#--dir:Monitoring of the mount point#--critical:critical value#--warning:warning value #--ip[ $# -eq 0 ] && {        echo "$0 [--dir PATH --critical NUM --warning NUM -h|--help]"        exit 99}while [ $# -ne 0 ];docase $1 in        -h|--help)                echo "$0 [--dir PATH --critical NUM --warning NUM -h|--help]"        --dir)                DIR=$2        --critical)                CRITICAL=$2                shift 2                ;;        --warning)                WARNING=$2                shift 2                ;;        --ip)                IP=$2                shift 2                ;;        *)                echo "$0 [--dir PATH --critical NUM --warning NUM -h|--help]"                exit 99                ;;esacdoneUSEAGE=`df -h|awk -v mount=$DIR ‘$NF==mount{print $(NF-1)}‘|cut -d% -f1`if [ $USEAGE -ge $CRITICAL ];then        MSG="PROBLEM Service Alert:$IP:$DIR is CRITICAL,Used $USEAGE%"        /usr/local/bin/sendEmail -f FROMEMAIL -t TOEMAIL -s SMTPSERVER -u "SUBJECT" -xu YOURUSERNAME -xp YOUPASS -m  "$MSG"elif [ $USEAGE -ge $WARNING ];then        MSG="PROBLEM Service Alert:$IP:$DIR is WARNING,Used $USEAGE%"        /usr/local/bin/sendEmail -f FROMEMAIL -t TOEMAIL -s SMTPSERVER -u "SUBJECT" -xu YOURUSERNAME -xp YOUPASS -m  "$MSG"fi


用法:./monitorBack.sh --dir /back --ip 192.168.1.100 --critical 90 --warning 70

本文出自 “diannaowa” 部落格,請務必保留此出處http://diannaowa.blog.51cto.com/3219919/1617262

shell指令碼監控分區使用率,並發郵件警示

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.