armsultan
12/2/2016 - 8:56 PM

A bash script runs a loop to read a random URL and user-agent from a file and runs a request using cURL. This can be run from any system tha

A bash script runs a loop to read a random URL and user-agent from a file and runs a request using cURL. This can be run from any system that cURL runs on

This can be used to "warm up" web application and populate cache

#!/bin/bash
## Warm Up script with Curl ##
# GIST https://gist.github.com/armsultan/e07b8737cd6cee28884a7a7d5372a034

# Mac users need shuf, install it with brew:
# 'brew install coreutils'
# shuf is gshuf on MAC. To use 'shuf', create an alias:
shuffle='gshuf'
# On Linux use shuf, comment line above and uncomment line below:
# shuffle='shuf'

# Requirements:
# Text File with Valid User-Agents, one per line in a file user-agents.txt
# Text File with Valid URLs, one per line in a file url-list.txt

#counter
i=1

# This runs a endless While loop. Hit Crtl - C to stop
trap "exit" INT

while :
do

        # Random User-Agent from File
        browserUA="$($shuffle -n 1 user-agents.txt)"

        # Random URL from File
        url="$($shuffle -n 1 url-list.txt)"
        #The $url contains a \r (CR) at the end (0d). Remove it with
        url=${url%$'\r'}

        # Print Test Parameters
        printf "RUN:$i\nURL = $url\nUA = $browserUA\n\n"
        Printf "Hit Ctrl+C to Stop\n\n"

        # Curl
        command="curl -s -A '"$browserUA"' '"$url"' > /dev/null"
        eval $command
        let i++

done