Shell script monitors partition usage, concurrent mail alerts

Source: Internet
Author: User

The recent use of a partition on the line was too fast, and Nagios did not turn on the monitoring of partition usage, taking a few minutes to temporarily write a script to use first. The usage is relatively simple, directly on the code:

Note: The SendEmail script used in the code is an e-mail program developed by Perl that can be found online or using other email scripts

#!/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 ];d ocase $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

Usage:./ 70--warning

This article is from the "Diannaowa" blog, make sure to keep this source

Shell script monitors partition usage, concurrent mail alerts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

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.