Linux 设置定时清除buff/cache的脚本


Linux 设置定时清除buff/cache的脚本

 

查看内存缓存状态

[root@heyong ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:          96406       19256       11311          66       65837       76421
Swap:          4095        1016        3079

  

清理缓存的脚本

[root@heyong ~]# vim /home/script/clear_buff_cache.sh
#!/bin/bash

#开始清理缓存
echo "开始清除缓存"

#写入硬盘,防止数据丢失
sync;sync;sync

#延迟10秒
sleep 10

#清理缓存
echo 3 > /proc/sys/vm/drop_caches

  

设置定时任务(每天凌晨2:30清理一次)

[root@heyong ~]# crontab -e

# clear buff/cache

30 2 * * * /home/script/clear_buff_cache.sh

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM