您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。