Skip to content

Instantly share code, notes, and snippets.

@JimHume
Created January 30, 2018 18:43
Show Gist options
  • Save JimHume/9a619985e320af88771d6ef9631016e2 to your computer and use it in GitHub Desktop.
Save JimHume/9a619985e320af88771d6ef9631016e2 to your computer and use it in GitHub Desktop.
A bash script to continuously curl a host, checking for a pattern/set of patterns in the result using grep. It prints random length noise at the end of the output to make it easier to see the text moving out of the corner of your eye--great for multiple (4) screens.
#!/bin/bash
function arg_or_default()
{
if [ -n "$1" ]; then
echo "$1"
else
echo "$2"
fi
}
function main()
{
while :
do
suffix=""
random_length=$(($RANDOM % $max_noise_length))
for (( noise_counter=0; noise_counter<$random_length; noise_counter++ ))
do
suffix="$suffix$noise_character"
done
curl_result="$(tput setaf 1)FAILURE$(tput sgr0)"
if [ -n "$(curl --silent --max-time $(($max_curl_time + 0)) $host_address | grep -E ""${grep_pattern}"" )" ]; then
curl_result="$(tput setaf 2)SUCCESS$(tput sgr0)"
fi
echo " - $curl_result $(date) $suffix"
sleep $sleep_time_between_calls
done
}
# Set the defaults for these or pass the variables via command line
host_address=$(arg_or_default "$1" "10.98.76.11")
max_noise_length=$(arg_or_default "$2" 9)
noise_character=$(arg_or_default "$3" "*")
grep_pattern=$(arg_or_default "$4" "<html.*35")
max_curl_time=$(arg_or_default "$5" 1)
sleep_time_between_calls=$(arg_or_default "$6" 2)
# Call the main function which curls/sleeps/rinse/repeats
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment