#!/bin/bash

# ------------------------------------------------------------------------------+
#                   HECK FILE SYSYTEM INODE BY THRESHOLD                        |
#   Filename: ck_fs_inode.sh                                                    |
#   Desc:                                                                       |
#      The script use to check file system inode by threshold                   |
#      Once usage of the inode beyond the threshold, a mail alert will be sent. |
#      Deploy it by crontab. e.g. per 15 min                                    |
#   Usage:                                                                      |
#      ./ck_fs_inode.sh <percent> </filesystem [/filesystem2]>                  |
#                                                                               |
#   Author : Kael_Wang                                                          |
#   Blog   : https://www.kael.wang                                               |
# ------------------------------------------------------------------------------+
#
# -------------------------------
#  Set environment here
# ------------------------------

if [ -f ~/.bash_profile ]; then
    . ~/.bash_profile
fi

export host=`hostname`
export mail_dir=/usr/local/bin
export mail_list='kael@kael.wang'
export mail_fm='sd168_zabbix@aspirecn.com'
tmpfile=/tmp/ck_fs_inode.txt
alert=n

# --------------------------------
#  Check the parameter
# --------------------------------

max=$1

if [ ! ${2} ]; then
    echo "No filesystems specified."
    echo "Usage: ck_fs_inode.sh 85 / /opt"
    exit 1
fi

# --------------------------------
#  Start to check the disk space
# --------------------------------

while [ "${2}" ]
    do
        percent=`df -i ${2} | tail -1 | awk '{print $5 }' | cut -d'%' -f1`
        if [ "${percent}" -ge "${max}" ]; then
            alert=y
            break
        fi;
        shift
    done;

# ------------------------------------------------------------------------
#  When a partition was above the threshold then send mail with df output
# ------------------------------------------------------------------------

if [ ! "${alert}" = 'n' ];then
    df -i >$tmpfile
    mail_sub="Dangerous!!!Disk Inode usage beyond the threshold ${max} on ${host}."
    $mail_dir/sendEmail -s 127.0.0.1 -u ${mail_sub} -f $mail_fm -t $mail_list -o message-file=${tmpfile}
fi;

exit;

定时任务添加

*/15 * * * * ./ck_fs_inode.sh 85 / /opt
分类: 发行通用

0 条评论

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注