[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 oldboy0987 "|nc 10.0.0.21 11211) get_mvalue=$(printf "get key008 "|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