日魂月魄

导航

centos使用shell定时清空缓存

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1.创建一个shell清空脚本

touch  clearCache.sh (创建脚本文件,任意路径)

#!/bin/bash

used=`free -m | awk 'NR==2' | awk '{print $3}'`

free=`free -m | awk 'NR==2' | awk '{print $4}'`

if [ $free -le 5500 ] ; then
  sync && echo 1 > /proc/sys/vm/drop_caches
  sync && echo 2 > /proc/sys/vm/drop_caches
  sync && echo 3 > /proc/sys/vm/drop_caches
  echo "OK" >> /var/spool/cron/delcache.log
else
  echo "Not required" >> /var/spool/cron/dropcache.log
fi

2.增加脚本权限

chmod +x dropcache.sh

3.将脚本增加到

 00 03 * * * /home/clearCache.sh

4.启动脚本

service crond star

service crond start 

posted on 2021-06-17 17:05  L-H  阅读(200)  评论(0编辑  收藏  举报