您好,登錄后才能下訂單哦!
下面講解經(jīng)典腳本案例,主要是借用其思路。
此種腳本最好用于nagios監(jiān)控,結(jié)合nagios監(jiān)控腳本比較好。
用法為#./shell/chk_mem.sh -w 數(shù)值臨界值 -c 數(shù)值臨界值
給定數(shù)值不同,腳本報(bào)出信息級(jí)別不同,由此判斷緊急情況。
#!/bin/bash STAT_OK=0 STAT_WARNING=1 STAT_CRITICAL=2 STAT_UNKNOWN=3 total_mem=`free -m |awk 'NR==2{print $2}'` used_mem=`free -m |awk 'NR==3{print $3}'` free_mem=`free -m |awk 'NR==3{print $4}'` use_per=`echo "scale=2;$used_mem/$total_mem"|bc|sed 's/^.//g'` #free_per=`echo "scale=2;$free_mem/$total_mem"|bc|sed 's/^.//g'` #echo "$use_per" help() { echo "USAGE:`basename $0` [-w] <used percent> [-c] <used percent> [-h]" exit -1 } while getopts ":w:c:h" opt do case $opt in w) warning=$OPTARG ;; c) critical=$OPTARG ;; h) help ;; ?) unkown=$OPTARG echo "error,plase check for help,USAGE:./`basename $0` -h" exit $STAT_UNKNOWN ;; esac done if [[ $use_per -lt $warning ]] then echo "OK - total:$total_mem MB,used:$used_mem MB,free:$free_mem MB | total_mem=$total_mem used_mem=$used_mem free_mem=$free_mem" exit $STAT_OK elif [[ $use_per -ge $warning ]] && [[ $use_per -lt $critical ]] then echo "WARNING - total:$total_mem MB,used:$used_mem MB,free:$free_mem MB | total_mem=$total_mem used_mem=$used_mem free_mem=$free_mem" exit $STAT_WARNING else echo "CRITICAL - total:$total_mem MB,used:$used_mem MB,free:$free_mem MB | total_mem=$total_mem used_mem=$used_mem free_mem=$free_mem" exit $STAT_CRITICAL fi fi
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。