您好,登錄后才能下訂單哦!
1.腳本如下~
- #!/bin/bash
- #=========================================
- #File: check_vm.sh
- #Description:
- #Author: smileliuyb
- #Modify: smileliuyb
- #Creation Date: 2013-1-14
- #Last Modified: 2013-1-14
- #=========================================
- #======check-arg===============
- if [[ $4 != "" ]];then
- echo $2 $4 | awk '$1 !~ /^[0-9]*[0-9,M,m,G,g]$/ || $2 !~ /^[0-9]*[0-9,m,g,M,G]$/{print "User like ./check_vm.sh -w freememory[M,G] -c freememory[M,G]";exit 3}'
- if [ $? -eq 3 ];then
- exit 3
- fi
- if [[ $1 == '-w' ]] && [[ $3 == '-c' ]];then
- warning=`echo $2 | awk '$1 ~ /[0-9]$/{print $1};$1 ~ /[m,M]$/{print $1*1024};$1 ~ /[g,G]$/{print $1*1024*1024}'`
- critical=`echo $4 | awk '$1 ~ /[0-9]$/{print $1};$1 ~ /[m,M]$/{print $1*1024};$1 ~ /[g,G]$/{print $1*1024*1024}'`
- elif [[ $1 == '-c' ]] && [[ $3 == '-w' ]];then
- warning=`echo $4 | awk '$1 ~ /[0-9]$/{print $1};$1 ~ /[m,M]$/{print $1*1024};$1 ~ /[g,G]$/{print $1*1024*1024}'`
- critical=`echo $2 | awk '$1 ~ /[0-9]$/{print $1};$1 ~ /[m,M]$/{print $1*1024};$1 ~ /[g,G]$/{print $1*1024*1024}'`
- else
- echo "User like ./check_vm.sh -w freememory[M,G] -c freememory[M,G]"
- exit 3
- fi
- else
- echo "User like ./check_vm.sh -w freememory[M,G] -c free[M,G]"
- exit 3
- fi
- #====see-mem and comparison with arg========
- freemem=`free -m | cut -d " " -f17`
- if [ $(( freemem*1024 )) -le $critical ];then
- echo "Insufficient memory,Only"$freemem"M are free!"
- exit 2
- elif [ $(( freemem*1024 )) -le $warning ];then
- echo "Memory Warning,Only"$freemem"M are free!"
- exit 1
- else
- echo "Memory OK"
- exit 0
- 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)容。