Bash script to monitor server HTTP output length and e-mail an alert

Pages: 1 2

This specific content was written 13 years ago. Please keep this in mind as it may be outdated and not adhering to best-practices.

IDScript

#!/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 "http://server1URL");
        a=$(./IDscript "http://scrupt2URL")$a;  #concatenate with previous output
        a=$(./IDscript "http://scrupt3URL")$a;

        lenA=$(expr length "$a");

        if [ $lenA -eq 0 ] #check length of A is empty
        then
                echo "No errors";
        else
                mail -s "TID error" [email protected] <<< "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!



Menelaos Bakopoulos

Menelaos Bakopoulos

Mr. Menelaos Bakopoulos is currently pursuing his PhD both at Center for TeleInFrastruktur (CTiF) at Aalborg University (AAU) in Denmark and Athens Information Technology (AIT) in Athens, Greece. He received a Master in Information Technology and Telecommunications Systems from Athens Information Technology and a B.Sc. in Computer Science & Management Information Systems from the American College of Thessaloniki. Since April 2008 he has been a member of the Multimedia, Knowledge, and Web Technologies Group.

More Posts