#!/bin/bash
buffer_cache=$(free - | awk 'NR==2' | awk '{print $6}' | tr -d '[:space:]') # 获取缓冲区和缓存的大小并去除空格
buffer_cache_mb=$(echo "scale=2; $buffer_cache / 1024" | bc) # 将KB转换为MB并保留两位小数
if (( $(echo "$buffer_cache_mb < 20480" | bc) )); then
echo "Buff/Cache is below 20G. No action required."
else
echo "Buff/Cache is above 20G. Dropping caches..."
sync
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
sync
fi
free -h发现cache/buffer过高时,执行下述相关命令(20G水平线)
最新推荐文章于 2024-05-20 15:19:16 发布