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

  

 

posted @ 2019-08-05 17:20  何宇泽  阅读(3532)  评论(0编辑  收藏  举报