检测内存的使用率

#!/bin/bash

mem=free -m |grep Mem |awk '{print $3/$2*100}' |awk -F. '{print $1}'

if [ $mem -ge 80 ];then
echo "Memory usage exceeds 80%."
read -p "Do you want to clean up the memory? [y/n] " answer
if [ $answer = y ];then
echo 3 > /proc/sys/vm/drop_caches
echo "Memory cleaning completion."
elif [ $answer = n ];then
echo "Exit."
else
echo "Input error."
fi
else
echo "The rate of use of memory is $mem%."
fi

猜你喜欢

转载自blog.51cto.com/13765357/2121355