linux中利用shell定时清理网站缓存数据库|linux中利用shell定时清理网站缓存数据脚本

时间:2020-09-24  来源:redis  阅读:

经过测试,脚本不成立!!

网站采用了一些方法进行加速(redis\cdn),这样就降低用户访问后端mysql的压力、以及前端速度不太好的问题,对用户请求到的所有页面进行了缓存,既然数据缓存了,解决用户看到的页面是否为最新页面就提上日程,下面这个脚本就诞生了。嘿嘿。。。
Shell

#!/bin/bash
# Author:Byrd
# Version:0.1
# Contact:root#t4x.org
# define category
for category in basic code database environment error mobile other project remark route service switch system
do
    for ((i=2;i<15;i++))
    do
        # Define return value
        RETURN=`curl -o /dev/null -s -k -w "%{http_code}" https://www.111cn.net /$category/page/$i/?r=y`
        if [ $RETURN -eq 200 ]; then
            # if return value 200,then flush page and category.
            curl -o /dev/null -s -k -w "%{http_code}" https://www.111cn.net /$category/page/$i/?r=y >/dev/null 2>&1
            curl -o /dev/null -s -k -w "%{http_code}" https://www.111cn.net /$category/?r=y >/dev/null 2>&1
        else
            # if return value not 200,then flush category first page and site page.break
            curl -o /dev/null -s -k -w "%{http_code}" https://www.111cn.net /$category/?r=y >/dev/null 2>&1
            curl -o /dev/null -s -k -w "%{http_code}" https://www.111cn.net /?r=y >/dev/null 2>&1
            break
        fi
    done
done

将脚本加入定时任务,由于网站不定期更新,更新不频繁,因此每天执行任务即可。

[root@site scripts]# echo "#flush cache" >>/var/spool/cron/root    #注释                                               
[root@site scripts]# echo "00 2 * * * /bin/sh /byrd/scripts/flush_site.sh >/dev/null 2>&1" >>/var/spool/cron/root    #两点执行计划任务                  
[root@site scripts]# crontab -l
#flush cache
00 2 * * * /bin/sh /byrd/scripts/flush_site.sh >/dev/null 2>&1

linux中利用shell定时清理网站缓存数据库|linux中利用shell定时清理网站缓存数据脚本

http://m.bbyears.com/shujuku/100635.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新