This is a quick post to show how one can issue commands to telnet session from a shell script or command line with out going into interactive mode. I use this to get stats from our memcache servers or issue a flush_all via telnet from a script/cron.
So without further delay, following command will telnet to local memcached server on port 11211 and issue one of the memcached commands, stats
(sleep .5;echo stats) | telnet localhost 11211
You may have to play with the sleep timer to get it to work for your environment but in our .5 was the sweet spot. Good luck and let me know if you have another shell command. Obviously we can do this from perl, php, python, etc but the beauty of this is that you do not need any other dependencies plus its a very short command.
Since “jsled” commented about nc (thanks jsled), here is the syntax to do the same thing with nc:
echo "stats" | nc localhost 11211
What’s the point of the sleep command?
You might want to look into netcat (nc) as a telnet alternative; it has a whole section of its manpage about “why not just use telnet to connect to arbitrary ports?”.
It allows telnet session to be opened before sending the command. I had some problems on some of the servers without sleep. In some cases, I even had to jack it up to .8 so it had enough time:
And since you mentioned the nc command, I will update the post with that command as well. Thanks.
Wait for the reply and then hang up:
echo “stats” | nc -w1 localhost 11211
# Wait for the reply and then hang up:
# echo â€œstatsâ€ | nc -w1 localhost 11211
That produces an error, since the ‘”‘ confuses memcached. The following does work:
echo stats | nc -w1 localhost 11211
(sleep .2; echo ‘GET cache_object://192.168.108.11:3128/info HTTP/1.0’;echo)|netcat -t localhost 3128
Thanks for the suggestions you are discussing on this web site. Another thing I’d prefer to say is the fact that getting hold of duplicates of your credit history in order to check out accuracy of each detail will be the first measures you have to carry out in fixing credit. You are looking to clear your credit profile from damaging details faults that wreck your credit score.