[4ajr@db1 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
[4ajr@db1 scripts]$ ./zookeeper_mode.sh
2
[4ajr@db1 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
[4ajr@db1 scripts]$ echo ruok|nc 127.0.0.1 2181
imok[4ajr@db1 scripts]$ ./zookeeper_status.sh
1