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