Using shell to periodically clean up Web cache data scripts in Linux

Source: Internet
Author: User
Tags curl flush

After testing, the script does not set up!!

The site uses a number of methods to accelerate (REDIS\CDN), this reduces user access to back-end MySQL pressure, as well as the front-end speed is not very good problem, the user requested to all the pages are cached, since the data cache, to solve the user saw the page is the latest page on the agenda, The following script is born. Hey...
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
Todo
For ((i=2;i<15;i++))
Todo
# 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 is not 200,then flush category-A-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

The script is added to the scheduled task, because the site is not regularly updated, the update is not frequent, so every day to carry out the task.

[Root@site scripts]# echo ' #flush cache ' >>/var/spool/cron/root    #注释                                                   
[Root@site scripts]# Echo 2 * * */bin/sh/byrd/scripts/flush_s ite.sh >/dev/null 2>&1 ' >>/var/spool/cron/root    #两点执行计划任务                    
[Root@site scripts]# Crontab-l
#flush Cache
2 * * */bin/sh/byrd/scripts/flush_site.sh >/dev/null 2>&1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.