forked from szepeviktor/debian-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload-cache.sh
executable file
·29 lines (25 loc) · 1.06 KB
/
preload-cache.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
#
# Loop through sitemap and preload cache by scraping the site.
# There is 1 second delay between requests.
#
# VERSION :0.3
# DATE :2015-04-16
# AUTHOR :Viktor Szépe <viktor@szepe.net>
# LICENSE :The MIT License (MIT)
# URL :https://github.com/szepeviktor/debian-server-tools
# BASH-VERSION :4.2+
# LOCATION :/usr/local/bin/preload-cache.sh
# SITEMAP="<SITE-URL>/sitemap.xml"
SITEMAP_URL="$1"
# ACCEPT_LANGUAGES="hu,en-us;q=0.7,en;q=0.3"
ACCEPT_LANGUAGES="$2"
[ -z "$ACCEPT_LANGUAGES" ] && ACCEPT_LANGUAGES="hu"
WGET_VER="$(wget -V | sed -n 's|.*Wget \([0-9.]\+\) .*|\1|p')"
USER_AGENT="Mozilla/5.0 (compatible; preload-cache/${WGET_VER}; +https://github.com/szepeviktor/debian-server-tools)"
# HTTP HEAD requests without retries
wget -q --user-agent="$USER_AGENT" -O- "$SITEMAP_URL" \
| sed -n 's|^.*<loc>\([^<]\+\)</loc>.*$|\1|gp' \
| wget --quiet --wait 1 --tries 1 --spider \
--user-agent="$USER_AGENT" --header="Accept-Language: ${ACCEPT_LANGUAGES}" --header="Accept-Encoding: gzip" \
-i -