#!/bin/bash

####################################################################################
##
##  Check if every config in server.conf is same on all hosts
##
##  ./check_config_on_all_hosts.sh [KEY]
##
##  If KEY is provoded, checks KEY only. Otherwise, checks all keys
##
#####################################################################################

if [[ ! -f "$HOME/.jaguarhome" ]]; then
	echo "Jaguar has not been installed, quit"
	exit 1
fi

unset LD_LIBRARY_PATH

myips=`hostname -I`

JAGUAR_HOME=`cat $HOME/.jaguarhome`
hostfile="$JAGUAR_HOME/conf/cluster.conf"
allhosts=`grep -v '#' $hostfile|grep -v '@'`

if [[ ! -f "$hostfile" ]]; then
    echo "$hostfile is not found, exit"
    exit 1
fi

for h in $allhosts; do

    if echo $myips |grep -q $h; then
        jh=$JAGUAR_HOME
	    echo "Local host $h $jh ..."
	    tail -10 $jh/log/jaguar.log
    else
        jh=`ssh $h 'if [ -f ~/.jaguarhome ]; then cat ~/.jaguarhome; else echo $HOME/jaguar; fi'`
	    echo "Host $h $jh ..."
	    ssh $h "tail -10 $jh/log/jaguar.log"
    fi

    echo
    echo
done

exit 0
