-
Notifications
You must be signed in to change notification settings - Fork 12
/
varnish-cache-warmer.sh
executable file
·31 lines (28 loc) · 1.07 KB
/
varnish-cache-warmer.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
30
31
#!/bin/bash
#
# Written by AC - 2015 <contact@chemaly.com> - sys0dm1n.com
#
# The URLs or IPs variables are passed as an argument to the script like below:
# ./varnish-cache-warmer.sh example1.com example2.com example3.com
VERSION='1.0.0'
USER_AGENT="VarnishCacheWarmer/$VERSION (see https://github.com/sys0dm1n/varnish-cache-warmer)"
warm_varnish() {
echo "Warming cache for $1"
curl -sL -A "$USER_AGENT" http://$1/sitemap.xml | egrep -o "http(s?)://$1[^ \"\'()\<>]+" | while read line; do
if [[ $line == *.xml ]]
then
newURL=$line
curl -sL -A "$USER_AGENT" $newURL | egrep -o "http(s?)://$1[^ \"\'()\<>]+" | while read newline; do
time curl -sL -A "$USER_AGENT" -sL -w "%{http_code} %{url_effective}\n" $newline -o /dev/null 2>&1
echo $newline
done
else
time curl -sL -A "$USER_AGENT" -sL -w "%{http_code} %{url_effective}\n" $line -o /dev/null 2>&1
echo $line
fi
done
echo "Done warming cache for $1"
}
for host in "$@"; do
warm_varnish $host
done