Regularly clean up cache

Scripting

#! /bin/sh
# 已使用的
used=`free -m | awk 'NR==2' | awk '{print $3}'`
# 空闲的
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "===========================" >> /home/mem/mem.log
date >> /home/mem/mem.log
echo "Memory usage before | [Use:${used}MB][Free:${free}MB]">> / Home / MEM / mem.log 
# 4g memory when idle or less, then clear the memory 
IF [$ Free -le 4096 ]; the 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 
  used_ok = ` Free -m | awk  ' NR == 2 ' | awk  ' {}. 3 Print $ ' ` 
  free_ok = ` Free -m | awk 'NR==2' | awk '{print $4}'`
  echo "Memory usage after | [Use:${used_ok}MB][Free:${free_ok}MB]" >> /home/mem/mem.log
  echo "OK" >> /home/mem/mem.log
else
  echo "Not required" >> /home/mem/mem.log
fi
exit 1

Add recurring task

crontab -e

Join (two in the morning to perform once a day)

1 2 * * * /home/mem/clearMemCache.sh

 

 View timers

crontab -l

 

 

ps: time configuration instructions

43  21 * * * day 21: 43 execution 

15  05 * * * day 05: 15 execution 

0  17 * * * day 17: 00 execution 

0  17 * * 1 every Monday 17 : 00 to perform 

0 , 10  17 * * 0 , 2 , 3 every Sunday, Tuesday, Wednesday 17 : 11:00 and 17 : 10 to perform 

0 - 10  17  1 * * from every 1 March 17 : 00-7: 10 every execution every 1 minutes 

0 0  1 , 15 * 1 every January 1 and 15 and day 0 : 00 executed 

42  4  1 * * each month 1 day 4 : 42 points execution 

0  21 * * 1 - 6   from Monday to Saturday 21 : 00 execution 

0 , 10 , 20 , 30 , 40 , 50 * * * *  every 10 minutes executed

 * / 10 * * * *         every 10 minutes execution

 * 1 * * * from 1: 0 to 1: 59 1 minute executed every 

0 1 * * *          1 : 00 performs 

0 * / 1 * * *         every time executed every hour 0 

0 * * * *          every time executed every 1 hour 0 

2  . 8 - 20 is / 3 * * *      . 8 : 02 , . 11 : 02 , 14 : 02 , . 17 : 02 , 20 is : 02 performs 

30  . 5  . 1 , 15 * and 15 * 1 May . 5 : 30 perform

 

Guess you like

Origin www.cnblogs.com/suruozhong/p/11975114.html