Skip to content

Instantly share code, notes, and snippets.

@thejustsoul
Forked from thomasfr/warmly.sh
Last active June 30, 2017 02:14
Show Gist options
  • Save thejustsoul/0fb6ef666cd4a90a523054e49317eb66 to your computer and use it in GitHub Desktop.
Save thejustsoul/0fb6ef666cd4a90a523054e49317eb66 to your computer and use it in GitHub Desktop.
A wget based easy poor man`s cache warmer script
#!/bin/bash
# warmly.sh
# A wget based, easy, poor man`s cache warmer script
# https://gist.github.com/thomasfr/7926314
# The MIT License (MIT)
#
# Copyright (c) 2013,2014 Thomas Fritz <[email protected]> (http://fritzthomas.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
CURRENT_WORKING_DIR="$(pwd)"
WARMLY_HOME="$(cd $(dirname $0);pwd)"
cd $CURRNT_WORKING_DIR
WARMLY_DEFAULT_USER_AGENT="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; WARMLY)"
WARMLY_USER_AGENT="${2:-$WARMLY_DEFAULT_USER_AGENT}"
WARMLY_START_URL="${1}"
WARMLY_WAIT_NEXT_RUN="600s"
WARMLY_WGET_LOGFILE="${WARMLY_HOME}/wget.log"
WARMLY_WAIT_SECONDS_BETWEEN_REQUESTS="0.5"
WARMLY_REJECT="gif,jpg,jpeg,png,pdf,txt,xml,ico,svg,css,js,json,zip,rar,doc,docx,xls,xlsx,ppt,pptx,rtf,tiff,odt,dts,odp,avi,flv,mp4,mp3,ogg,wav"
WARMLY_RUN=1
if [ -z $WARMLY_START_URL ]; then
echo "No starting url set"
exit 1
fi
echo "Using User-Agent: '$WARMLY_USER_AGENT'"
echo "Warmly starts here: '$WARMLY_START_URL'"
echo "$(date) START"
while :
do
echo "$(date) START RUN '#${WARMLY_RUN}'"
wget --no-cache -R ${WARMLY_REJECT} --wait=${WARMLY_WAIT_SECONDS_BETWEEN_REQUESTS} --limit-rate=400k --delete-after -r -nd -N -l 3 -t 3 -T 20 -nv -o "${WARMLY_WGET_LOGFILE}" -U "${WARMLY_USER_AGENT}" "${WARMLY_START_URL}"
if [ $? -gt 0 ] ; then
exit 1;
fi
echo "$(date) WAIT '${WARMLY_WAIT_NEXT_RUN}' for next run"
sleep "${WARMLY_WAIT_NEXT_RUN}"
let "WARMLY_RUN=WARMLY_RUN+1"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment