View Zookeeper cluster status with shell scripts

Source: Internet
Author: User
Tags zookeeper
Zooper Cluster Structure:
Host name role
Node1 Follower
Node2 leader
Node3 Follower
Master Observer
Script content:
#!/bin/bash
function GetStatus () {
#定义一个函数
EXEC 9<>/dev/tcp/$1/2181 2>/dev/null
#打开host的port a read-write socket connection that is connected to the file descriptor 9
Echo Stat >&9
#将 "Stat" sent to the socket connection
mode=$ (Cat <&9 |grep-po "(? <=mode:). ")
#从socket返回数据中提取Mode的值 and assign a value to mode
EXEC 9<&-#关闭通道
Echo ${mode:-null}
#输出MODE *
}
For i in node{1..3} nn01;do
Echo-ne "${i}\t"

  • #输出i, do not wrap and TAB key to make a space
    GetStatus ${i}
    #执行函数 GetStatus and assign values to positional variables *
    Done

Script Execution Results:
Node1 Follower
Node2 leader
Node3 Follower
Master Observer

View Zookeeper cluster status with shell scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.