#!/bin/bash # This test will verify if the system has some determined conditions # to execute any OurGrid set of tests. # # Are conditions to run the tests: # - The user must edit his test.properties file. # - Cannot be using the selected ports in mg.port and og.port. # - Must set all the files in 'bin' as executable and same to a # script at test directory. # - Must set a valid and writable System Temp Dir. # - All grid machines selected must be visible (and online). # # After this verification, the script will try to fix some of those # problems (except those who need to be setted by the user). # TEST_BASE=2 TEST_IFMACHINEISALIVE=$[TEST_BASE + 1]; TEST_MACHINESSH=$[TEST_BASE + 2]; TOTAL_ALIVE=0 TOTAL_ALIVE_SSH=0 NUMBER_OF_MACHINES=0 TESTCHECK=`basename $0` BOOTUP=color SETCOLOR_SUCCESS="echo -en \\033[1;32m" SETCOLOR_FAILURE="echo -en \\033[1;31m" SETCOLOR_WARNING="echo -en \\033[1;33m" SETCOLOR_NORMAL="echo -en \\033[0;39m" gprintf() { if [ -x /bin/gettext -a -n "$1" ]; then if [ -n "$GP_LANG" ]; then local TEXT=`LANGUAGE=$GP_LANG gettext -e --domain=$TEXTDOMAIN "$1"` else local TEXT=`gettext -e --domain=$TEXTDOMAIN "$1"` fi else local TEXT=$1 fi [ "${1#*\\n}" ] || TEXT="$TEXT\n" shift printf "$TEXT" "$@" } echo_success() { RES_COL=$1 MOVE_TO_COL="echo -en \\033[${RES_COL}G" [ "$BOOTUP" = "color" ] && $MOVE_TO_COL echo -n "[" [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS gprintf " OK " [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo -n "] " } echo_failure() { RES_COL=$1 MOVE_TO_COL="echo -en \\033[${RES_COL}G" [ "$BOOTUP" = "color" ] && $MOVE_TO_COL echo -n "[" [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE gprintf "FAIL" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo -n "] " } echo_uanotrunning() { RES_COL=$1 MOVE_TO_COL="echo -en \\033[${RES_COL}G" [ "$BOOTUP" = "color" ] && $MOVE_TO_COL echo -n "[" [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE gprintf "UANotRun" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo -n "] " } echo_unavailable() { RES_COL=$1 MOVE_TO_COL="echo -en \\033[${RES_COL}G" [ "$BOOTUP" = "color" ] && $MOVE_TO_COL echo -n "[" [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE gprintf "NotAvail" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo -n "] " } echo_value() { RES_COL=$1 MOVE_TO_COL="echo -en \\033[${RES_COL}G" [ "$BOOTUP" = "color" ] && $MOVE_TO_COL echo -n "[" [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE gprintf "$2" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo -n "] " } plot () { echo -n "$1" COL=15 echo -en "\\033[${COL}G" echo -n "$2" COL=45 echo -en "\\033[${COL}G" echo -n "$3" } check_lsd_machines() { dir=`dirname $0` machinelist="$dir/machinesbyusers" COL1=62 COL2=72 COL3=82 COL4=92 # open $machinelist file and assign file descriptor 3 to it exec 3<$machinelist plot "ROOM" "MACHINE" "OWNER" echo -en "\\033[${COL1}G" echo -n "Alive?" echo -en "\\033[${COL2}G" echo -n " SSH?" echo -en "\\033[${COL3}G" echo -n " RMI?" echo -en "\\033[${COL4}G" echo "duration" while IFS=: read room machine so owner <&3 do NUMBER_OF_MACHINES=$[NUMBER_OF_MACHINES + 1] plot "$room" "$machine" "$owner" ping -c 1 -t 1 $machine &> /dev/null if [ $? -ne 0 ]; then ALIVE=0 echo_failure $COL1 echo_failure $COL2 else ALIVE=1 TOTAL_ALIVE=$[TOTAL_ALIVE+1] echo_success $COL1 #Can connect to it? # print_question $TEST_MACHINESSH $machine ssh -o StrictHostKeyChecking=no \ -o ConnectTimeout=5 \ -o PreferredAuthentications=hostbased,publickey \ $machine exit 2> /dev/null if [ $? -ne 0 ]; then SSH_ALIVE=1 echo_failure $COL2 else SSH_ALIVE=0 TOTAL_SSH_ALIVE=$[TOTAL_SSH_ALIVE+1] echo_success $COL2 fi fi rmi_init=$(date +%s) java -cp .:"$dir/../../lib/ourgrid.jar:$dir" RMILookup rmi://$machine:8568/UserAgent ret=$? rmi_end=$(date +%s) rmi_time=$[rmi_end - rmi_init] if [ $ret -eq 0 ]; then echo_success $COL3 else if [ $ret -eq 1 ]; then echo_uanotrunning $COL3 else # equals to 2 echo_unavailable $COL3 fi fi echo_value $COL4 $rmi_time echo done exec 3>&- # Now close it for the remainder of the script. } clear echo "--------------------------------------------------------------------------" echo " Testing all LSD machine" echo "--------------------------------------------------------------------------" rm -f $0.out init_time=$(date +%s) check_lsd_machines end_time=$(date +%s) echo "--------------------------------------------------------------------------" gprintf "Machines ALIVE = " $SETCOLOR_SUCCESS gprintf "$TOTAL_ALIVE" $SETCOLOR_NORMAL gprintf "/$NUMBER_OF_MACHINES" echo gprintf "Machines DOWN = " $SETCOLOR_FAILURE gprintf $[NUMBER_OF_MACHINES - TOTAL_ALIVE] $SETCOLOR_NORMAL gprintf "/$NUMBER_OF_MACHINES" echo gprintf "Machines Linux = " $SETCOLOR_SUCCESS gprintf "$TOTAL_SSH_ALIVE" $SETCOLOR_NORMAL gprintf "/$NUMBER_OF_MACHINES" echo gprintf "Machines Windows = " $SETCOLOR_FAILURE gprintf $[TOTAL_ALIVE - TOTAL_SSH_ALIVE] $SETCOLOR_NORMAL gprintf "/$NUMBER_OF_MACHINES" echo gprintf "Total amount of time for checking machines = " gprintf $[end_time - init_time] echo echo "--------------------------------------------------------------------------"