13 memcache服务检查

[root@cache01 scripts]# vim mem_check.sh 

#!/bin/bash

count_mem=$(netstat -lntup|grep memcached|wc -l)


function get_set() {
        set_mvalue=$(printf "set key008 0 5 10\r\noldboy0987\r\n"|nc 10.0.0.21 11211)
        get_mvalue=$(printf "get key008\r\n"|nc 10.0.0.21 11211|wc -l)

        ${set_mvalue} &>/dev/null
        echo "${get_mvalue}"        
        if [ ${get_mvalue} -gt 1 ]
        then
                echo "memcached 服务set get 正常"
        else
                echo "mem 的set get 失败"
        fi


}
if [ ${count_mem} -eq 4 ]
then
        get_set
else

        echo "服务没有启动,将重启服务,再次检查"
        systemctl start memcached.service
        sleep 3
        get_set

fi

 

 

posted @ 2017-12-07 14:41  滴滴滴  阅读(200)  评论(0编辑  收藏  举报