Hello

I'm writing a script to get content of web pages on different machines and compare them using their md5 hash

hear is my code

#!/bin/bash

# Cluster 1
CLUSTER1_SERVERS="srv01:7051 srv02:7052 srv03:7053 srv04:7054"
CLUSTER1_APPLIS="test/version.html test2/version.html test3/version.jsp test4/version.html test5/version.jsp"

# Cluster 2
CLUSTER2_SERVERS="srv01:7055 srv02:7056 srv03:7057 srv04:7058"
CLUSTER2_APPLIS="test/version.html test2/version.html test3/version.jsp test4/version.html"

# Cluster 4
CLUSTER4_SERVERS="srv01:7063 srv02:7064 srv03:7065 srv04:7066"
CLUSTER4_APPLIS="test/version.html test2/version.html"

# Liste des clusters �* tester
CLUSTERS="CLUSTER1 CLUSTER2 CLUSTER4"

# init vars
CRITICAL=2
WARNING=1
OK=0

for cluster in $CLUSTERS
do
        for server in $(eval echo \$${cluster}_SERVERS)
        do
        server_name=`echo $server | cut -d':' -f1,1`
        server_port=`echo $server | cut -d':' -f2,2`
        for applis in $(eval echo \$${cluster}_APPLIS)
        do
            checksum=`curl --silent --write-out '%{http_code}\n' "http://$server_name:$server_port/$applis" | md5sum`
            if [[ ( "$checksum" -ne "$checksum1" ) ]]
            then
            exit_code=2
            else
            exit_code=0
            fi
        done
    done
done

case $exit_code in
        "2")
                echo "CRITICAL - App Version Mismatch"
                exit $CRITICAL
                ;;
        "0")
                echo "OK - All apps deployed are identical"
                exit $OK
                ;;
        *)
                echo "CRITICAL - there's something wrong with this script ..."
                exit $CRITICAL
                ;;
esac

getting web pages content and generation md5 hash works perfectly

but I'm a blocked when comparing them

if [[ ( "$checksum" -ne "$checksum" ) ]]

can you guide me how i could accomplish this

thanks in advance
gtam

hi,

first, you could avoid eval by using an assosciative array.

next, remove parenthesis from "improved test" ([[); you could also use simple test.

finally, remove trailing spaces and dash from checksums

checksum="${checksum%% *}"

hello,

thanks of you reply

ok i corrected these points, see the below code

for cluster in $CLUSTERS
do
        for server in $(eval echo \$${cluster}_SERVERS)
        do
                server_name=$(echo $server | cut -d':' -f1,1)
                server_port=$(echo $server | cut -d':' -f2,2)
                for applis in $(eval echo \$${cluster}_APPLIS)
                do
                        checksum=$(curl --silent --write-out '%{http_code}\n' "http://$server_name:$server_port/$applis" | md5sum)
                        if [[ ( "$checksum" -ne "$checksum" ) ]]
                        then
                        exit_code=2
                        else
                        exit_code=0
                        fi
                done
        done
done

my issue here is i dont know / understand how i could compare md5 hash of each web pages

any idea or sugessions

you can't compare more than two things. :(

you must have a referent (a "main page" against which the other pages will be compared to) !

and again :
- you could avoid eval by using an assosciative array.
- remove parenthesis from "improved test" ([[); you could also use simple test.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.