1

I'm working on a bash script for another question I'm asking. Here's what I have:

exec 3<>/dev/tcp/m.m.0001.u.cache.amazonaws.com/11211
echo -e "get CacheCleaner\nquit" >&3
cat <&3

It works, almost. It returns this:

VALUE CacheCleaner 0 1
1
END

What I don't have the stills to do, is take the 1 on the middle line, and put it into a variable.

I tried editing the >&3, and I have some idea what that does, but I'm a bit lost.


Based on How to store standard error in a variable in a Bash script

It looks like I can do:

exec 3<>/dev/tcp/m.m.0001.u.cache.amazonaws.com/11211
echo -e "get CacheCleaner\nquit" >&3
CC=`cat <&3` 
echo $CC

This returns:

ENDE CacheCleaner 0 1

So not really what I need, but closer.

Community
  • 1
  • 1
Beachhouse
  • 4,972
  • 3
  • 25
  • 39

3 Answers3

1
dos2unix <&3 | sed -n 2p

The output appears to have \r\n line ending sequences. The dos2unix command converts \r\n to \n which is the UNIX style of line ending.

The sed command prints the second line of the output.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • I saw you posted this in one of your edits: tr '\r' '\n' <&3 | sed -n 2p. Bingo – Beachhouse Jan 09 '13 at 18:45
  • I see your point on the dos2unix though, which makes no real sense to me because both servers are running centos. I just changed it to -n 3p and I'm pulling the third line. – Beachhouse Jan 09 '13 at 18:51
  • 1
    @Beachhouse The HTTP protocol uses `\r\n` line endings even when the webserver is a Linux machine. I'm guessing Amazon's server speaks (or mimics) HTTP. – John Kugelman Jan 09 '13 at 18:54
  • it does. Memcache runs as an HTTP server. Thanks for the clarification. – Beachhouse Jan 09 '13 at 18:56
1

What about this?

CC=$(cat <&3 | sed -n 2p)

jgr
  • 3,914
  • 2
  • 24
  • 28
1
# instead of cat, do this
read a a a a result a <&3
echo $result
DigitalRoss
  • 143,651
  • 25
  • 248
  • 329