[Ocfs2-tools-devel] [PATCH 12/12] A new ocfs2 configure file
vertify tool
Xiaowei Hu
xiaowei.hu at oracle.com
Wed Jan 30 01:26:16 PST 2008
---
scripts/o2cb_verify.sh | 944 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 944 insertions(+), 0 deletions(-)
create mode 100755 scripts/o2cb_verify.sh
diff --git a/scripts/o2cb_verify.sh b/scripts/o2cb_verify.sh
new file mode 100755
index 0000000..271de67
--- /dev/null
+++ b/scripts/o2cb_verify.sh
@@ -0,0 +1,944 @@
+#!/bin/bash
+
+# An OCFS2 configure file vertify tool.
+
+# * Copyright (C) 2008 Oracle. All rights reserved.
+# *
+# * This program is free software; you can redistribute it and/or
+# * modify it under the terms of the GNU General Public
+# * License, version 2, as published by the Free Software Foundation.
+# *
+# * This program is distributed in the hope that it will be useful,
+# * but WITHOUT ANY WARRANTY; without even the implied warranty of
+# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# * General Public License for more details.
+# *
+# * You should have received a copy of the GNU General Public
+# * License along with this program; if not, write to the
+# * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# * Boston, MA 021110-1307, USA.
+
+VERSION=1.2.7-2
+
+CONFIG_FILE="/etc/ocfs2/cluster.conf"
+DATE=`date +%s`
+TEMP_DIR="/tmp/ocfs2/cluster_verif/$DATE"
+ERRLOG="$TEMP_DIR/error.log"
+IP_ADDR_FILE="$TEMP_DIR/local_ip_addr_info"
+
+PURESYNATX=0
+DEBUG=0
+VERBOSE=0
+
+COLLECT_LOOP=1
+PRINT_LOOP=2
+
+SSHSUC=0
+SSH_CMD_FAILED=1
+SSHLOCAL=253
+SSHSKIP=254
+SSHERR=255
+
+# If the length of $USER is 0,ssh will connect with current user name.
+USER=
+TIMEOUT=5
+COMMAND="hostname;cat $CONFIG_FILE"
+
+NODE_ALIVE=1
+NODE_HOSTNAME=2
+NODE_SYNC=3 #need sync -1 no need-0
+
+NODE_INDEX=1
+CLUSTER_INDEX=2
+
+IP_PORT_INDEX=1
+IP_ADDRESS_INDEX=2
+NODE_NAME_INDEX=3
+NODE_NUMBER_INDEX=4
+NODE_CLUSTER_INDEX=5
+
+CLUSTER_NAME_INDEX=1
+NODE_COUNT_INDEX=2
+
+VALID=1
+UNKNOWN=1
+INVALID=0
+#node and cluster properties' names array
+NODE_PRO=(0 ip_port ip_address name number cluster)
+CLUSTER_PRO=(0 name node_count)
+
+
+display_help()
+{
+ echo "Usage:"
+ echo -e "\t`basename $0` [options] [filename]"
+ echo -e "\tfilename:Defines the location of configure file,default is /etc/ocfs2/cluster.conf."
+ echo "Options:"
+ #echo -e "\t-d:Debug mode."
+ echo -e "\t-h:Display this screen."
+ echo -e "\t-o outputfile:Output to the file with name of outputfile."
+ echo -e "\t-s:Pure syntax check mode,without checks using ssh,default is off."
+ echo -e "\t-v:Verbose mode,output more information."
+}
+#check parameters.
+while getopts 'do:svh' OPTION;
+do
+ case $OPTION in
+ d) #echo "DEBUG mode"
+ DEBUG=$VALID
+ ;;
+ o) echo "Output is saved to the file:$OPTARG,check this file for results."
+ exec 1> $OPTARG
+ ;;
+ s) #echo "Pure Syntax check mode"
+ PURESYNATX=$VALID
+ ;;
+ v) #echo "Verbose mode"
+ VERBOSE=$VALID
+ ;;
+ h) echo "Usage:"
+ echo -e "\t`basename $0` [options] [filename]"
+ echo -e "\tfilename:Defines the location of configure file,default is /etc/ocfs2/cluster.conf."
+ echo "Options:"
+ #echo -e "\t-d:Debug mode."
+ echo -e "\t-h:Display this screen."
+ echo -e "\t-o outputfile:Output to the file with name of outputfile."
+ echo -e "\t-s:Pure syntax check mode,without checks using ssh,default is off."
+ echo -e "\t-v:Verbose mode,output more information."
+ exit
+ ;;
+ *) echo "Simple use example:./o2cb_verify.sh /etc/ocfs2/cluster.conf"
+ echo "For more help please use the -h option!"
+ exit
+ ;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+if [[ -n $1 ]]
+then
+ CONFIG_FILE=$1
+else
+ echo "Simple use example:./o2cb_verify.sh /etc/ocfs2/cluster.conf"
+ echo "For more help please use the -h option!"
+ exit
+fi
+# check_ident match the valid identifier, if match return $VALID,else $INVALID
+# parameter:
+# $1 - the identifier get from configure file.
+# $2 - expected identifier, non-case-sensitive.
+check_ident()
+{
+ if (echo $1|egrep -i "^[[:blank:]]+$2[[:blank:]]*=[[:blank:]]*[[:alnum:]_.@]*[[:blank:]]*">/dev/null)
+ then
+ return $VALID
+ else
+ return $INVALID
+ fi
+}
+
+# Get corresponding value from a line
+# parameter:
+# $1 - one line get from the configure file
+# return:
+# will echo the result to the stdout.
+get_value()
+{
+ local index
+ local substr
+ local len
+ local count
+ len=$(expr length $1)
+ #echo $len
+ index=$(( $(expr index $1 '=') + 1 ))
+ count=$(( len - index + 1 ))
+ substr=$(expr substr $1 $index $count)
+ substr=$(expr $substr : '[[:blank:]]*\(.*\)[[:blank:]]*')
+ echo $substr
+ return 0
+}
+
+# Get the index in the arrays of nodes[]&clusers[]
+# parameter:
+# $1 - $NODEX_INDEX or $CLUSTER_INDEX,defined at the begin of this file.
+# $2 - $node_num or $cluster_num value at that moment.
+# $3 - The index type value $IP_PORT_INDEX or $IP_ADDRESS_INDEX etc,defined at begin of this file.
+# return:
+# The index value
+get_index()
+{
+ local index
+ if (( $1 == $NODE_INDEX ))
+ then
+ (( index = ($2 - 1) * 5 + $3 ))
+ echo $index
+ return $VALID
+ elif (( $1 == $CLUSTER_INDEX ))
+ then
+ index=`get_cluster_index $2 $3`
+ echo $index
+ return $VALID
+ fi
+}
+
+# Get the index in clusters[] array.
+# parameter:
+# $1 - $cluster_num
+# $2 - $CLUSTER_NAME_INDEX/$NODE_COUNT_INDEX
+get_cluster_index()
+{
+ local index
+ (( index = ($1 - 1) * 2 + $2 ))
+ echo $index
+ return $VALID
+}
+
+# Get the index in array nodes_ssh[]
+# parameter:
+# $1 - $node_num
+# $2 - $NODE_ALVIE/$NODE_HOSTNAME/$NODE_SYNC
+# return:
+# The index value
+get_ssh_index()
+{
+ local index
+ (( index = ($1 - 1) * 3 + $2 ))
+ echo $index
+ return $VALID
+}
+
+# For the nodes sections,check if the values of node's properties are valid.
+# If not will out put the error.
+# parameter:
+# $1 - the value kind want to check, like $NODE_CLUSTER_INDEX/$NODE_NAME_INDEX etc.
+# $2 - $node_num $cluster_count
+process_node()
+{
+ local value
+ local index
+ if (( $DEBUG == $VALID ))
+ then
+ echo "--node_num:$2--property index$1--"
+ fi
+ index=`get_index $NODE_INDEX $2 $1`
+ #echo $index
+ if (( $loop == $COLLECT_LOOP ))
+ then
+ ((isten=node_num%10))
+ if (( $isten == 0 ))
+ then
+ echo -n "|"
+ fi
+ value=`get_value $line`
+ if (( $DEBUG == $VALID ))
+ then
+ echo "Storing ${NODE_PRO[$1]} for node$2 = $value ,array index is $index"
+ fi
+ nodes[$index]=$value
+ fi
+ #echo ${nodes[$index]}
+ #echo "$line node_num=$node_num"
+ #continue
+ if (( $loop == $PRINT_LOOP ))
+ then
+ value=${nodes[$index]}
+ case $1 in
+ #probe wrong case for the values;
+ $IP_PORT_INDEX)
+ if ( check_port $value;(( $? == $INVALID )) )
+ then
+ echo -e "$line\e[0;31m......[Please check this ip_port value]\e[0m"
+ continue
+ fi;;
+ $IP_ADDRESS_INDEX)
+ if ( check_ip $value;(( $? == $INVALID )) )
+ then
+ echo -e "$line\e[0;31m......[Please check this ip_address value]\e[0m"
+ continue
+ fi;;
+ $NODE_NAME_INDEX)
+ if ( check_node_name $value $2;(( $? == $INVALID )) )
+ then
+ echo -e "$line\e[0;31m......[Please check this node_name value]\e[0m"
+ continue
+ fi;;
+ $NODE_NUMBER_INDEX)
+ if ( check_number $value $2;(( $? == $INVALID )) )
+ then
+ echo -e "$line\e[0;31m......[Please check this node number value]\e[0m"
+ continue
+ fi;;
+ $NODE_CLUSTER_INDEX)
+ if ( check_cluster $value $2 $3;(( $? == $INVALID )) )
+ then
+ echo -e "$line\e[0;31m......[Please check this cluster name value]\e[0m"
+ continue
+ fi;;
+ *)
+ echo "BUG in process_node():please report this to the dev team.";;
+ esac
+ fi
+
+ return 0
+}
+
+# Almost the same with process_node(),but checking values in cluster section.
+# parameter:
+# $1 - $NODE_COUNT_INDEX or $CLUSTER_NAME_INDEX
+# $2 - $cluster_num at that time
+process_cluster()
+{
+ local value
+ index=`get_index $CLUSTER_INDEX $2 $1`
+ #echo $index
+ value=`get_value $line`
+ #echo $value
+ if (( $loop == $COLLECT_LOOP ))
+ then
+ clusters[$index]=$value
+ fi
+ if (( $loop == $PRINT_LOOP ))
+ then
+ value=${clusters[$index]}
+ case $1 in
+ $CLUSTER_NAME_INDEX)
+ if ( check_cluster_name $value;(( $? == $INVALID )) )
+ then
+ echo -e "$line\e[0;31m......[Please check this cluster name value]\e[0m"
+ continue
+ fi;;
+ $NODE_COUNT_INDEX)
+ if ( check_node_count $value $2;(( $? == $INVALID )) )
+ then
+ echo -e "$line\e[0;31m......[Please check this node_count value,should be ${cluster_st[$2]}?]\e[0m"
+ continue
+ fi;;
+ *)
+ echo "BUG in process_cluster():please report this to the dev team.";;
+ esac
+ fi
+ #echo ${nodes[$index]}
+ #echo "$line node_num=$node_num"
+ #continue
+ return 0
+}
+
+# Check the ip_port value in node section.
+# parameter:
+# $1 - the value from the get_value().
+# return:
+# If valid return $VALID,else $INVALID.
+check_port()
+{
+ #echo "---$1---"
+ #if (echo $1|egrep -i "[^0-9]">/dev/null)
+ #then
+ # return $INVALID
+ #fi
+ if ( (echo $1|egrep -i "[^0-9]">/dev/null) || [[ -z $1 ]] || (($1 < 1024)) || (($1 > 65535)) )
+ then
+ return $INVALID
+ else
+ return $VALID
+ fi
+}
+
+# Check the ip_address value in node section.
+# parameter:
+# $1 - the value from the get_value().
+# return:
+# If valid return $VALID,else $INVALID.
+check_ip()
+{
+ local part1
+ local part2
+ local part3
+ local part4
+ #echo "---$1---"
+ if (echo $1|egrep "^([0-9]{1,3}\.){3}[0-9]{1,3}$">/dev/null)
+ then
+ part1=`echo $1|awk 'BEGIN{FS="."}{print $1}'`
+ part2=`echo $1|awk 'BEGIN{FS="."}{print $2}'`
+ part3=`echo $1|awk 'BEGIN{FS="."}{print $3}'`
+ part4=`echo $1|awk 'BEGIN{FS="."}{print $4}'`
+ #echo "$part1-$part2-$part3-$part4"
+ if ( (($part1 < 255)) && (($part2 < 255)) && (($part3 < 255)) && (($part4 < 255)) )
+ then
+ return $VALID
+ fi
+ fi
+ return $INVALID
+}
+
+# Check the number value in node section.
+# parameter:
+# $1 - the value from the get_value().
+# $2 - the value the $node_num variable at this moment.
+# return:
+# If valid return $VALID,else $INVALID.
+check_number()
+{
+ local ret
+ if ( [[ -n $1 ]] && (( $1 < 255 && $1 > 0 )) )
+ then
+ for (( i=1;i < $2;i += 1 ))
+ do
+ ret=`get_index $NODE_INDEX $i $NODE_NUMBER_INDEX`
+ if (( $1 == ${nodes[$ret]} ))
+ then
+ return $INVALID
+ fi
+ done
+ return $VALID
+ fi
+ return $INVALID
+}
+
+# Check the node_name value through ssh in node section.
+# parameter:
+# $1 - the value from the get_value().
+# $2 - the value the $node_num variable at this moment.
+# return:
+# If valid return $VALID,else $INVALID.
+check_node_name()
+{
+ local index
+ index=`get_ssh_index $2 $NODE_HOSTNAME`
+ if [[ $1 = ${nodes_ssh[$?]} ]]
+ then
+ return $VALID
+ elif (echo $1|egrep ".+">/dev/null)
+ then
+ return $UNKNOWN
+ fi
+ return $INVALID
+}
+
+# Check the cluster value according to the cluster name got from loop1 in node section.
+# parameter:
+# $1 - the value from the get_value().
+# $2 - the value the $cluster_count variable,including the total cluster number.
+# return:
+# If valid return $VALID,else $INVALID.
+check_cluster()
+{
+ local index
+ for (( i=1;i <= $2;i += 1 ))
+ do
+ index=`get_index $CLUSTER_INDEX $i $CLUSTER_NAME_INDEX`
+ if [[ $1 = ${clusters[$index]} ]]
+ then
+ return $VALID
+ fi
+ done
+
+ return $INVALID
+}
+
+# Check the cluster name value in cluster section.
+# parameter:
+# $1 - the value from the get_value().
+# return:
+# If valid return $VALID,else $INVALID.
+check_cluster_name()
+{
+ if (echo $1|egrep ".+">/dev/null)
+ then
+ return $VALID
+ fi
+ return $INVALID
+}
+
+# Used to check the node_count value in cluster sections.
+# cluster_st[] is counting the node number with the same cluster name.
+# para:
+# $1 - the value from the get_value().
+# $2 - cluster_num being checked.
+# return:
+# If valid return $VALID,else $INVALID.
+check_node_count()
+{
+ if (( $1 == ${cluster_st[$2]} ))
+ then
+ return $VALID
+ fi
+ return $INVALID
+}
+
+# Used to check if there is some properties missed in node or cluster sections.
+# para:
+# $1 - $NODE_INDEX or $CLUSTER_INDEX
+# $2 - $cluster_num or $node_num being checked.
+# return:
+# If valid return $VALID,else $INVALID.
+missing_warning()
+{
+ local proindex
+ local index
+ if (( $1 == $NODE_INDEX ))
+ then
+ for (( proindex=1; proindex <= $NODE_CLUSTER_INDEX; proindex++ ))
+ do
+ index=`get_index $1 $2 $proindex`
+ if [[ -z ${nodes[$index]} ]]
+ then
+ echo -e "\t\e[0;33mWarning:missing ${NODE_PRO[$proindex]} for this node\e[0m"
+ fi
+ done
+ elif (( $1 == $CLUSTER_INDEX ))
+ then
+ for (( proindex=1; proindex <= $NODE_COUNT_INDEX; proindex++ ))
+ do
+ index=`get_index $1 $2 $proindex`
+ if [[ -z ${clusters[$index]} ]]
+ then
+ echo -e "\t\e[0;33mWarning:missing ${CLUSTER_PRO[$proindex]} for this cluster\e[0m"
+ fi
+ done
+ else
+ echo "BUG:invalid index in missing_warning()"
+ fi
+}
+
+# connect to the remote nodes throught ssh,and got the hostname and cluster.conf file content.
+# on that node.
+# parameter:
+# $1 - the ip address of one node
+# Return:
+# $SSHSKIP - if the ip address is invalid or can connect in el4.
+# $ret - else the return value from ssh.
+get_ssh()
+{
+ if ( is_local_node $1;(( $? == $VALID )) )
+ then
+ if (( $DEBUG == $VALID ))
+ then
+ echo "get_ssh():Local node found!"
+ fi
+ eval hostname;cat $CONFIG_FILE 1> "$TEMP_DIR/$1" 2>>$ERRLOG
+ ret=$?
+ if (( $ret == $INVALID ))
+ then
+ return $SSHLOCAL
+ else
+ echo "Error,please check if the config file exist on this node!"
+ return $ret
+ fi
+ else
+ if ( check_ip $1;(( $? == $VALID ))&&(( $PURESYNATX == $INVALID )) )
+ then
+ #echo "connecting"
+ if [[ -f "$TEMP_DIR/$value" ]]
+ then
+ echo -e "$line\e[0;31m......[Duplicated ip_address!]\e[0m"
+ continue
+ else
+ #echo "sshing.............."
+ #echo "$TEMP_DIR/$1"
+ #echo "$COMMAND"
+ #The ssh command returns different error code in el4 and el5,
+ #ssh the non-exist address could help to decide which ssh is being used.
+ if [[ -n $USER ]]
+ then
+ connect_str="$USER@$1"
+ if (( $DEBUG == $VALID ))
+ then
+ echo "get_ssh():connect_string=$connect_str"
+ fi
+ else
+ connect_str="$1"
+ if (( $DEBUG == $VALID ))
+ then
+ echo "get_ssh():connect_string=$connect_str"
+ fi
+ fi
+ ssh 255.255.255.255>/dev/null 2>&1
+ if (( $? == 1 ))
+ then
+ ssh -oConnectTimeout=$TIMEOUT "$connect_str" $COMMAND 1> "$TEMP_DIR/$1" 2>>$ERRLOG
+ ret=$?
+ tail -2 $ERRLOG |grep 'unreachable'
+ if (( $? == 0 ))
+ then
+ return $SSHERR
+ else
+ return $ret
+ fi
+ else
+ ssh -oConnectTimeout=$TIMEOUT "$connect_str" $COMMAND 1> "$TEMP_DIR/$1" 2>>$ERRLOG
+ return $?
+ fi
+ fi
+ fi
+ fi
+ return $SSHSKIP
+}
+
+
+get_ifconfig()
+{
+ if (( $DEBUG == $VALID ))
+ then
+ echo "Getting ip address info..."
+ fi
+ /sbin/ifconfig > "$IP_ADDR_FILE"
+ cat $IP_ADDR_FILE
+}
+
+is_local_node()
+{
+ if (( $DEBUG == $VALID ))
+ then
+ echo "grep the ip address info file..."
+ fi
+ if ( grep $1 $IP_ADDR_FILE )
+ then
+ if (( $DEBUG == $VALID ))
+ then
+ echo "found $1 in the file"
+ fi
+ return $VALID
+ fi
+ if (( $DEBUG == $VALID ))
+ then
+ echo "not found $1 in the ip file"
+ fi
+ return $INVALID
+}
+
+if [[ -r $CONFIG_FILE ]]
+then
+ if [[ -d "$TEMP_DIR" ]]
+ then
+ rm -f -r $TEMP_DIR
+ fi
+ mkdir -p $TEMP_DIR
+ get_ifconfig
+ IFS=';'
+ #declare value
+ #declare index
+ declare -a cluster_st
+ declare -a clusters
+ declare -a nodes
+ declare -a nodes_ssh
+ cluster_count=$INVALID
+ node_count=$INVALID
+
+ loop=$COLLECT_LOOP
+ # to determine how to display,need to know some information advance.
+ # so at least loop twice.
+ # one for collect information,one for out put result to screen.
+ while (( $loop <= $PRINT_LOOP ))
+ do
+
+ cluster_num=$INVALID
+ node_num=$INVALID
+ node_match=$INVALID
+ cluster_match=$INVALID
+ match=$INVALID
+ node_err=$INVALID
+ cluster_err=$INVALID
+ section=$INVALID
+
+ linenum=$INVALID
+ match=$INVALID
+ node_match=$INVALID
+ cluster_match=$INVALID
+ check_missing=$INVALID
+
+ if (( $loop == $COLLECT_LOOP ))
+ then
+ echo "Processing,this may take a few mins for large cluster,please wait."
+ else
+ echo
+ fi
+
+ while read line
+ do
+ (( linenum = linenum + 1 ))
+ index=$INVALID
+
+ if (echo $line|egrep "^[[:blank:]]*#+">/dev/null || \
+ echo $line|egrep "^[[:blank:]]*$">/dev/null)
+ then
+ #remove blank and comment lines
+ #echo "$line"
+ (( linenum = linenum - 1 ))
+ continue
+ fi
+ if (echo $line|egrep -i "^node:[[:blank:]]*">/dev/null)
+ then
+ (( node_num++ ))
+ (( node_err=$node_num ))
+ (( cluster_err=$cluster_num ))
+ node_match=$VALID
+ cluster_match=$INVALID
+ section=$NODE_INDEX
+ check_missing=$NODE_INDEX
+ #echo $node_err
+ if (( $loop == $PRINT_LOOP ))
+ then
+ index=`get_ssh_index $node_num $NODE_ALIVE`
+ if (( ${nodes_ssh[$index]} <= $SSH_CMD_FAILED ))
+ then
+ index=`get_ssh_index $node_num $NODE_SYNC`
+ if (( ${nodes_ssh[$index]} == $VALID ))
+ then
+ echo -e "$line \e[0;32m[ALIVE] but \e[0;33m[Need Synchronization]\e[0m"
+ else
+ echo -e "$line \e[0;32m[ALIVE] and \e[0;32m[No Need Synchronization]\e[0m"
+ fi
+ else
+ if (( ${nodes_ssh[$index]} == $SSHLOCAL ))
+ then
+ echo -e "$line \e[0;32m[THIS NODE] \e[0m"
+ else
+ echo -e "$line \e[0;33m[SKIPPED.Unreachable through SSH]\e[0m"
+ fi
+ fi
+ fi
+ continue
+ fi
+
+ if (echo $line|egrep -i "^cluster:[[:blank:]]*">/dev/null)
+ then
+ (( cluster_num++ ))
+ (( node_err=$node_num ))
+ (( cluster_err=$cluster_num ))
+ #echo $cluster_err
+ node_match=$INVALID
+ cluster_match=$VALID
+ section=$CLUSTER_INDEX
+ check_missing=$CLUSTER_INDEX
+ if (( $loop == $PRINT_LOOP ))
+ then
+ echo "$line"
+ fi
+ continue
+ fi
+ #If the first line is an unknown identifier,then script will stop in process_node,
+ #for the node_num==0,but get_index need a positive value.So if this happen,prevent
+ #script run into the process_node() function.
+ if (( $node_num == 0 && $cluster_num == 0 ))
+ then
+ match=$INVALID
+ node_match=$INVALID
+ cluster_match=$INVALID
+ (( node_err++ ))
+ (( cluster_err++ ))
+ fi
+
+ if [[ $loop == $PRINT_LOOP && $check_missing != $INVALID ]]
+ then
+ if (( $check_missing == $NODE_INDEX ))
+ then
+ missing_warning $NODE_INDEX $node_num
+ elif (( $check_missing == $CLUSTER_INDEX ))
+ then
+ missing_warning $CLUSTER_INDEX $cluster_num
+ fi
+
+ check_missing=$INVALID
+ fi
+
+ if [[ $node_err == $node_num && $cluster_err == $cluster_num ]]
+ then
+
+ if ( check_ident $line "ip_port";(( $? == $VALID )) )
+ then
+ match=$VALID
+ process_node $IP_PORT_INDEX $node_num
+ elif ( check_ident $line "ip_address";(( $? == $VALID )) )
+ then
+ match=$VALID
+ process_node $IP_ADDRESS_INDEX $node_num
+ elif ( check_ident $line "number";(( $? == $VALID )) )
+ then
+ match=$VALID
+ process_node $NODE_NUMBER_INDEX $node_num
+ elif ( check_ident $line "cluster";(( $? == $VALID )) )
+ then
+ match=$VALID
+ process_node $NODE_CLUSTER_INDEX $node_num $cluster_count
+ elif ( check_ident $line "name";(( $? == $VALID )) )
+ then
+ match=$VALID
+ if (( section == $NODE_INDEX ))
+ then
+ process_node $NODE_NAME_INDEX $node_num
+ elif (( section == $CLUSTER_INDEX ))
+ then
+ process_cluster $CLUSTER_NAME_INDEX $cluster_num
+ else
+ if (( $loop == $PRINT_LOOP ))
+ then
+ echo -e "$line \e[31m[ERROR:The \"name\" property \
+ should in a valid node or cluster section!]\e[0m"
+ fi
+ continue
+ fi
+
+ elif ( check_ident $line "node_count";(( $? == $VALID )) )
+ then
+ match=$VALID
+ process_cluster $NODE_COUNT_INDEX $cluster_num
+ else
+ match=$INVALID
+ node_match=$INVALID
+ cluster_match=$INVALID
+ fi
+ fi
+
+ #if (echo $line|egrep "[[:blank:]]*[cluster node]*:[[:blank:]]*">/dev/null)
+ #then
+ # (( section++ ))
+ # echo $section
+ #echo "$line" #node_num=$node_num
+ #fi
+
+ #for all lines,determine how to display
+ if (( $loop == $PRINT_LOOP ))
+ then
+
+ if (( node_match == $INVALID && cluster_match == $INVALID && match == $INVALID ))
+ then
+ if (echo $line|egrep -i "[[:blank:]]*[cluster node]+:[[:blank:]]*">/dev/null)
+ # unknown identifer and willing it to be a node: or cluster:
+ then
+ (( node_err++ ))
+ (( cluster_err++ ))
+ else
+ if (( $node_num == 0 && $cluster_num == 0 ))
+ then
+ echo -e "$line\e[0;31m......[Unknown section,SKIPPED]\e[0m"
+ continue
+ fi
+ echo -e "$line\e[0;31m......[Unknown identifier]\e[0m"
+ continue
+ fi
+ fi
+
+ if (( node_err > node_num||cluster_err > cluster_num ))
+ then
+ echo -e "$line\e[0;31m......[Please check this section identifier]\e[0m"
+ continue
+ fi
+
+ if (( $DEBUG == 1 ))
+ then
+ echo "$line node_num=$node_num cluster_num=$cluster_num"
+ else
+ echo "$line"
+ fi
+
+ fi
+
+
+ done < $CONFIG_FILE
+
+ #get ssh in loop1
+ if (( $loop == $COLLECT_LOOP ))
+ then
+ node_count=$node_num
+ cluster_count=$cluster_num
+
+ for (( j=1;j <= $cluster_count;j += 1 ))
+ do
+ cluster_st[$j]=0
+ done
+
+ for ((i=1;i <= (( $node_num ));i += 1 ))
+ do
+ #echo ${nodes[$i]}
+ index=`get_index $NODE_INDEX $i $IP_ADDRESS_INDEX`
+ ip=${nodes[$index]}
+ if (( $DEBUG == $VALID ))
+ then
+ echo "Connecting node $ip."
+ fi
+ get_ssh $ip
+ ssh_ret=$?
+ #echo $ssh_ret
+ ssh_index=`get_ssh_index $i $NODE_ALIVE`
+ nodes_ssh[$ssh_index]=$ssh_ret
+
+ if (( $ssh_ret == $SSHERR ))
+ then
+ if (( $VERBOSE == $VALID ))
+ then
+ echo -e "\e[0;33mThe node whose ip address is $ip is unreachable.[SKIPPED]\e[0m"
+ fi
+ elif (( $ssh_ret == $SSHSKIP ))
+ then
+ if (( $VERBOSE == $VALID ))
+ then
+ echo -e "\e[0;33mThe node whose ip address is $ip is invalid.[SKIPPED]\e[0m"
+ fi
+ else
+ if (( $VERBOSE == $VALID ))
+ then
+ echo -e "\e[0;32mNode $ip connected.\e[0m"
+ fi
+ ssh_index=`get_ssh_index $i $NODE_HOSTNAME`
+ nodes_ssh[$ssh_index]=`head -1 "$TEMP_DIR/$ip"`
+ #echo ${nodes_ssh[$ssh_index]}
+ if (( $ssh_ret == $SSH_CMD_FAILED ))
+ then
+ echo "File $CONFIG_FILE doesn't exist on node $ip"
+ fi
+ sed '1d' "$TEMP_DIR/$ip" >| "$TEMP_DIR/$i" 2>|$ERRLOG
+ rm -f "$TEMP_DIR/$ip" 1>/dev/null 2>|$ERRLOG
+ ssh_index=`get_ssh_index $i $NODE_SYNC`
+ if (( $ssh_ret == $SSHLOCAL ))
+ then
+ nodes_ssh[$ssh_index]=$ssh_ret
+ else
+ diff -B --brief "$CONFIG_FILE" "$TEMP_DIR/$i" 1>/dev/null 2>|$ERRLOG
+ nodes_ssh[$ssh_index]=$?
+ fi
+ fi
+
+ index=`get_index $NODE_INDEX $i $NODE_CLUSTER_INDEX`
+ cluster=${nodes[$index]}
+ #echo "---$cluster---"
+
+ for (( j=1;j <= $cluster_count;j += 1 ))
+ do
+ index=`get_index $CLUSTER_INDEX $j $CLUSTER_NAME_INDEX`
+ if [[ $cluster = ${clusters[$index]} ]]
+ then
+ #echo ${cluster_st[$j]}
+ (( cluster_st[$j] += 1 ))
+ #echo ${cluster_st[$j]}
+ fi
+ done
+ done
+ fi
+
+ if (( $DEBUG == $VALID ))
+ then
+ echo "------Array:nodes:------"
+ for ((i=1;i <= (( $node_count*5 ));i += 1 ))
+ do
+ echo ${nodes[$i]}
+ done
+ echo "------Array:clusters:------"
+ for ((i=1;i <= (( $cluster_count*2 ));i += 1 ))
+ do
+ echo ${clusters[$i]}
+ done
+ echo "------Array:nodes_ssh:------"
+ for ((i=1;i <= (( $node_count*3 ));i += 1 ))
+ do
+ echo ${nodes_ssh[$i]}
+ done
+ fi
+ (( loop = $loop + 1 ))
+ done
+
+ rm -f -r $TEMP_DIR
+
+else
+ echo -e "\e[0;31mERROR:configure file:$CONFIG_FILE does not exist or not readable now.\e[0m"
+fi
+exit 0
--
1.5.3
More information about the Ocfs2-tools-devel
mailing list