wget warm drupal cache

October 8, 2012

Objective: Warm Drupal Cache

I wrote this script to warm the cache of a drupal site

Script Contents


#!/bin/bash -ex

# Locate the binaries
MKDIR="$(which mkdir)"
RM="$(which rm)"
WGET="$(which wget)"
#************************************
#### YOU MUST DEFINE THESE
PATH_CACHE_ROOT="/root/some_dir_name_to_store_data"
PATH_LOG_FILE="/root/wget.log"
URL_TO_CACHE="https://brakertech.com"
USER_AGENT="Mozilla/5.0 (X11; U; Linux; en-US; rv:1.9.1.16) Gecko/20110929 Firefox/3.5.16"
#************************************


# Remove cache directory if it exists
if [  -d $PATH_CACHE_ROOT ]
then
        $RM -rf $PATH_CACHE_ROOT
fi

if [ -f $PATH_LOG_FILE ]
then
        $RM -f $PATH_LOG_FILE
fi

#CREATE NEW CACHE DIR
$MKDIR $PATH_CACHE_ROOT

$WGET -U $USER_AGENT -r -l 2 -nc -p -E -k -np --no-check-certificate -P $PATH_CACHE_ROOT -o $PATH_LOG_FILE -q $URL_TO_CACHE


####COMMANDS EXPLAINED
#-U --user-agent
#-r --recursive
#-l  --level=depth
#-nc --no-clobber
#-p --page-requisites
#-E --html-extension
#-k convert-links
#-np --no-parent
#-P --directory-prefix
#-o --output-file (log file)
#-q --quiet