您好,登錄后才能下訂單哦!
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。