-
-
Save signalwerk/5d386f6813f1628cbf25cb9591f812b8 to your computer and use it in GitHub Desktop.
wget based cache warmer script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# RUN | |
# CACHE_WARMER_LOGFILE=~/cache_warmer.log bash <(curl -# -L http://bit.ly/signalwerk-warmly) https://xyz.com | |
# wget based cache warmer script | |
# Original Author: Thomas Fritz | |
# https://gist.github.com/thomasfr/7926314 | |
CURRENT_DIR="$(pwd)" | |
SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)" | |
cd "$CURRENT_DIR" | |
DEFAULT_USER_AGENT="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; CACHE_WARMER)" | |
USER_AGENT="${2:-$DEFAULT_USER_AGENT}" | |
START_URL="${1}" | |
WAIT_NEXT_RUN="600s" | |
WGET_LOGFILE="${CACHE_WARMER_LOGFILE:-$SCRIPT_DIR/wget.log}" | |
WAIT_BETWEEN_REQUESTS="0.5" | |
REJECT_EXTENSIONS="gif,jpg,jpeg,png,pdf,txt,xml,ico,svg,css,js,json" | |
RUN_COUNT=1 | |
if [ -z "$START_URL" ]; then | |
echo "No starting URL set" | |
exit 1 | |
fi | |
echo "Using User-Agent: '$USER_AGENT'" | |
echo "Cache warming starts at: '$START_URL'" | |
echo "$(date) START" | |
while :; do | |
echo "$(date) START RUN #${RUN_COUNT}" | |
wget --no-cache \ | |
--reject="${REJECT_EXTENSIONS}" \ | |
--wait="${WAIT_BETWEEN_REQUESTS}" \ | |
--limit-rate=400k \ | |
--delete-after \ | |
--recursive \ | |
--no-directories \ | |
--timestamping \ | |
--level=3 \ | |
--tries=3 \ | |
--timeout=20 \ | |
--no-verbose \ | |
--output-file="${WGET_LOGFILE}" \ | |
--user-agent="${USER_AGENT}" \ | |
"${START_URL}" | |
if [ $? -gt 0 ]; then | |
exit 1 | |
fi | |
echo "$(date) WAIT '${WAIT_NEXT_RUN}' for next run" | |
sleep "${WAIT_NEXT_RUN}" | |
let "RUN_COUNT=RUN_COUNT+1" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment