#!/usr/bin/env bash # # Forkload performs rudimentary load testing on remote web applications # Copyright (C) 2014 Aaron Ball # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # function get_help { echo " The forkload script provides rudimentary load testing for web applications (anything accessible through curl). This currently tests from a single system, so a significant bottleneck will occur due to the fact that a load test is running off of a single nic. As such, Forkload is intended for small scale load tests (tens to the low hundreds of clients, depending on your nic and the infrastructure between the testing agent and the target). Arguments: -t,--target Target to test -o,--output File to output the load test results to (default: forkload.out) -c,--clients Number of virtual clients to test with (default: 1) -h,--help Prints this help text " } function main { argv=(${@}) out="forkload.out" clients=1 target="" # Parse arguments for (( i = 0; i < ${#argv[*]}; i++ )); do val=${argv[$i]} if [[ ${val} == "-h" || ${val} == "--help" ]]; then echo -e "$(get_help)" exit 0 elif [[ ${val} == "-o" || ${val} == "--output" ]]; then i=$((i+1)) out=${argv[$i]} elif [[ ${val} == "-c" || ${val} == "--clients" ]]; then i=$((i+1)) clients=${argv[$i]} elif [[ ${val} == "-t" || ${val} == "--target" ]]; then i=$((i+1)) target=${argv[$i]} fi done # Verify needed variables if [[ -z ${target} ]]; then echo -e "\nPlease specify a target URL to test (-t,--target)." echo -e "See the help text (-h,--help) for more details.\n" exit fi # Clean up the out file :> ${out} for (( i = 0; i < ${clients}; i++ )); do echo "Client ${i}"; # Fork, time the page download { ( time curl -s ${target} > /dev/null & ) } 2>> ${out} done } main "${@}"