做Clusterware和RAC的测试的时候,节点多的时候,需要不停的在节点之间切换,而且容易出错,于是写了这样一个脚本,跟大家分享一下。
目前主要完成一些简单的功能,支持的平台有Linux,Solaris, AIX and HP,打算继续扩展。也欢迎使用并提出意见,
[ractest@sun880-1 ~]$ more console #!/bin/bash #This script is used to control the whole cluster nodes in one interface echo "******************************************************************" echo " Welcome to Cluster Console " echo " " echo "The console is used to control the whole cluster nodes in one node" echo "now it can support start/stop stack,check stack status, process " echo "priority, check node uptime and will support more in the future " echo " " echo " Any bug or comment please report to ricky.zhu@gmail.com " echo "******************************************************************" get_nodename () { $CH/bin/olsnodes -n > tmp name=`head -n $1 tmp | tail -1 | awk '{print $1}'` echo "$name" } check_uptime() { nl=`$CH/bin/olsnodes ` for node in $nl do echo "node=$node" $RSH $node "hostname; date; /usr/bin/uptime" done } UNAME='/bin/uname' PLATFORM=`$UNAME` <span id="more-444"></span> case $PLATFORM in SunOS) RSH=/usr/bin/rsh SSH=/usr/bin/ssh GREP=/usr/xpg4/bin/grep PSEF="/usr/bin/ps -cafe" ;; Linux) RSH=/usr/bin/rsh SSH=/usr/bin/ssh GREP=/bin/grep PSEF="/bin/ps -cafe" ;; HP-UX) RSH=/usr/bin/remsh SSH=/usr/bin/ssh GREP=/usr/bin/grep PSEF="/usr/bin/ps -afe" CH=$CRS_HOME ;; AIX) RSH=/bin/rsh SSH=/bin/ssh GREP=/bin/grep PSEF="/bin/ps -afe" CH=$CRS_HOME ;; esac nodelist=`$CH/bin/olsnodes` nl="$nodelist All" PS3="Please select node: " TITLE="\******************************************************************/" select node in $nl do PS3="Please select command: " # name=`get_nodename $node` name=$node if [[ $node == "All" ]] then select command in "Start the crs stack" "Stop the crs stack" "Back" "Quit" do case $command in "Start the crs stack") echo $TITLE echo "Now to start crs on node: $name" for name in $nodelist do $RSH $name "hostname; date; $CH/bin/crsctl start crs" done echo $TITLE ;; "Stop the crs stack") echo $TITLE echo "Now to stop crs on node: $name" for name in $nodelist do $RSH $name "hostname; date; $CH/bin/crsctl stop crs" done echo $TITLE ;; "Back") PS3="Please select node: " echo "Back to cluster node list" break ;; Quit) echo "Quit. Thanks for using." exit 0 ;; esac done fi $RSH $name date if [[ $? == 0 ]] then RSH=$RSH else RSH=$SSH fi select command in "Start the crs stack" "Stop the crs stack" "Check stack status" "Check process priority" "Check node uptime" " Back to nodelist" "User command" "Enable the crs next reboot" "Disable the crs next reboot" "Stop ASM instance" "Start ASM instance" "Start nodeapps" "Stop nodeapps" "Start listener" "Stop listener" "Quit" do case $command in "Start the crs stack") echo $TITLE echo "Now to start crs on node: $name" $RSH $name "hostname; date; $CH/bin/crsctl start crs" echo $TITLE ;; "Stop the crs stack") echo $TITLE echo "Now to stop crs on node: $name" $RSH $name "hostname; date; $CH/bin/crsctl stop crs" echo $TITLE ;; "Check stack status") echo $TITLE echo "Now to check crs on node: $name" $RSH $name "hostname; date; $CH/bin/crs_stat -t -v" echo $TITLE ;; "Check process priority") echo $TITLE echo "Now check priority on node: $name" $RSH $name "hostname;date; $PSEF | $GREP -e lmon -e dlm -e ucmm -e ocssd.bin -e oclsomon -e oprocd -e oclsvmon -e lms -e lmo n | $GREP -v grep | $GREP -v tail" echo $TITLE ;; "Check node uptime") echo $TITLE echo "Now check all node uptime" check_uptime; echo $TITLE ;; "User command") echo $TITLE echo "Input your command" read cmd source .profile; $RSH $name "hostname; date; $cmd" echo $TITLE ;; "Back to nodelist") PS3="Please select node: " echo "Back to cluster node list" break ;; "Enable the crs next reboot") echo $TITLE echo "Now enable crs on next reboot on node: $name" $RSH $name "hostname;date; /etc/init.d/init.crs enable" echo $TITLE ;; "Disable the crs next reboot") echo $TITLE echo "Now disable crs on next reboot on node: $name" $RSH $name "hostname;date; /etc/init.d/init.crs disable" echo $TITLE ;; "Stop ASM instance") echo $TITLE echo "Now stop ASM instance on node: $name" $RSH $name "hostname;date; $CH/bin/srvctl stop asm -n $name" echo $TITLE ;; "Start ASM instance") echo $TITLE echo "Now start ASM instance on node: $name" $RSH $name "hostname;date; $CH/bin/srvctl start asm -n $name" echo $TITLE ;; "Start nodeapps") echo $TITLE echo "Now start nodeapps on node: $name" $RSH $name "hostname;date; $CH/bin/srvctl start nodeapps -n $name" echo $TITLE ;; "Stop nodeapps") echo $TITLE echo "Now stop nodeapps on node: $name" $RSH $name "hostname;date; $CH/bin/srvctl stop nodeapps -n $name" echo $TITLE ;; "Stop listener") echo $TITLE echo "Now stop listener on node: $name" $RSH $name "hostname;date; $CH/bin/srvctl stop listener -n $name" echo $TITLE ;; "Start listener") echo $TITLE echo "Now start listener on node: $name" $RSH $name "hostname;date; $CH/bin/srvctl start listener -n $name" echo $TITLE ;; Quit) echo "Quit. Thanks for using." exit 0 ;; *) echo "$REPLY is not one of your choice" 1>&2 ;; esac done done |