[[email protected] scripts]$ cat zookeeper_mode.sh
#!/bin/bash
mode=`echo srvr|nc 127.0.0.1 2181| awk’/Mode/{print $2}’`
if [[ “$mode” == “follower” ]]; then
echo 1
elif [[ “$mode” == “leader” ]]; then
echo 2
else
echo 0
fi
[[email protected] scripts]$ ./zookeeper_mode.sh
2
[[email protected] scripts]$ cat zookeeper_status.sh
#!/bin/bash
zk=`echo ruok|nc 127.0.0.1 2181`
if [[ “$zk” == “imok” ]]; then
echo 1
else
echo 0
fi
[[email protected] scripts]$ echo ruok|nc 127.0.0.1 2181
imok[[email protected] scripts]$ ./zookeeper_status.sh
1
< /p>