Created
January 31, 2024 07:02
-
-
Save AGou-ops/293038ecd67c47aa6fb68bab99876b54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 获取总内存大小 | |
total_mem=$(free -m | awk 'NR==2{print $2}') | |
# 获取buff/cache大小 | |
buff_cache=$(free -m | awk 'NR==2{print $6}') | |
# 计算buff/cache占总内存的百分比 | |
usage_percentage=$((buff_cache * 100 / total_mem)) | |
echo $total_mem $buff_cache $usage_percentage | |
# 判断是否超过60% | |
if [ $usage_percentage -gt 60 ]; then | |
echo "Buff/Cache usage is above 60%. Cleaning buff/cache..." | |
# 执行清理buff/cache的命令,例如使用sync和echo 3 > /proc/sys/vm/drop_caches | |
sync && echo 3 > /proc/sys/vm/drop_caches | |
echo "Buff/Cache cleaned." | |
else | |
echo "Buff/Cache usage is below 60%. No action needed." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
crontab: