Below is a script I wrote today to use CURL to monitor the length of various HTTP server outputs and output a response if this is different than 103 characters. This is my first bash script, so I had some reading/experimenting to do and it is quite rough. The idea is that if there are no errors, my php script will ouput exactly 103 characters. If there are errors, this will be increased.
#!/bin/bash # Check for missing IDs - greater output than 103 characters cd "/media/SMALL/scripts" if [[ -z "$1" ]] # check if script arguement exists then a=$(./IDscript "server"); a=$(./IDscript "server2")$a; #concatenate with previous output a=$(./IDscript "server3")$a; lenA=$(expr length "$a"); if [ $lenA -eq 0 ] #check length of A is empty then echo "No errors"; else mail -s "TID error" myEmail@company.org <<< "There are errors:"$a; # send the e-mail fi exit; fi #create random number from 50 to 99 r=$(( $RANDOM % 50 + 50 )); #bypass HTTP proxy with random number testURL=$1"/checkError?which=IDError&rand="$r; curlOut=$(curl -s "$testURL"); curlLength=$(expr length "$curlOut"); if [ $curlLength -ne 103 ] #103 char is response length when no missing IDs exist then echo "length is not 103:"$testURL; echo -e "\n"; fi
Comments and suggestions are welcome!