shell判断内存使用率告警

#!/usr/bin/bash
########################################
#memory used
#v1.0 by LIXIN 20180605
########################################
mem_used=free -m |grep '^Mem' |awk '{print $3}'
mem=free -m |grep 'Mem' |awk '{print $2}'
mem_usage=$((mem_used100/mem))
warning_file=/tmp/mem_warning.txt
rm -f /tmp/
_warning*
if [ "$mem_usage" -ge 20 ]; then

    echo  "memory's warning `date +%F-%H` memory:$mem_usage%" > $warning_file

fi

if [ -f $warning_file ];then
mail -s "memory warning......" -a $warning_file [email protected] < $warning_file
rm -f /tmp/_warning
fi

猜你喜欢

转载自blog.51cto.com/13620507/2125274
今日推荐