Skip to content

Instantly share code, notes, and snippets.

@serac
Created September 2, 2016 11:50
Show Gist options
  • Save serac/7bba39e70a983b2b2d21245072b0bd05 to your computer and use it in GitHub Desktop.
Save serac/7bba39e70a983b2b2d21245072b0bd05 to your computer and use it in GitHub Desktop.
Bash script to get a key from a list of memcached hosts, testing each one in turn
#!/bin/bash
function getkey {
echo "Checking $M for $2"
HOST=$(echo $1 | cut -d':' -f1)
PORT=$(echo $1 | cut -d':' -f2)
echo "get $2" | nc -w1 $HOST $PORT
}
if [ $# -lt 1 ]; then
echo "USAGE: $(basename $0) keyname"
exit
fi
trap "exit" SIGINT SIGTERM
IFS=','
for M in $MEMCACHED_HOSTS; do
getkey $M $1
done
unset IFS
@serac
Copy link
Author

serac commented Sep 2, 2016

Usage Example:

export MEMCACHED_HOSTS="a.example.com:11211,b.example.com:11211"
memcached-get somekey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment