#! /usr/bin/bash #author:lhf #effect:Memory utilization declare -A ARRAY1 ARRAY1[t_memory]=`free -m|grep -i "mem"|tr -s " "|cut -d " " -f2` echo "总内存:${ARRAY1[t_memory]}" ARRAY1[u_memory]=`free -m|grep -i "mem"|tr -s " "|cut -d " " -f3` echo "已用内存:${ARRAY1[u_memory]}" ARRAY1[usages_memory]=`echo "${ARRAY1[u_memory]}*100/${ARRAY1[t_memory]}"|bc` if [ $? -gt 0 ];then echo "脚本未执行成功是否安装程序bc继续执行" echo "Y/S" read A if [ $A = Y ];then yum install bc -y clear echo " *********************************** " else echo "正在退出脚本" sleep 2 exit 0 fi fi echo "内存使用率:`echo "scale=2;${ARRAY1[u_memory]}*100/${ARRAY1[t_memory]}"|bc`%" if [[ ${usages_memory} -ge 70 ]];then echo -e "\033[31m内存使用率过大请尽快处理\033[0m" else echo "内存使用率健康" fi
检测内存使用率的shell脚本
判断内存使用率的脚本,初学者,如有问题多谢指出
0
0
0
精彩评论