Search code examples
bashshellautomationmemcached

How to get memcached stats without nc?


this is how I'm getting the stats now: echo -e "stats\nquit" | nc 127.0.0.1 11211

I can't use expect as it's not part of a default installation.

Is there a way to get memcached stats without nc?


Solution

  • Your question doesn't specify why you're looking for an alternative to netcat, so it's hard to to tell what you're looking for. You could do it in bash like this:

    exec 3<>/dev/tcp/127.0.0.1/11211
    echo -e "stats\nquit" >&3
    cat <&3
    

    You could do it using telnet:

    (echo -e 'stats\nquit'; sleep 1) | telnet localhost 11211
    

    The sleep is to precent telnet from exiting before receiving a response from memcached.

    You could also write something simple in python or perl or some other high level scripting language. Or brush up on your c. There are lots of options.