我正试图从使用netcat的memcached服务器收集统计信息。
~ $nc 10.251.170.80 11211 stats STAT pid 27508 STAT uptime 7940345 STAT time 1262949310 STAT version 1.2.4 STAT pointer_size 64 STAT rusage_user 1389.962693 STAT rusage_system 4857.247586 STAT curr_items 9154565 STAT total_items 615722800 STAT bytes 1994844049 STAT curr_connections 62 STAT total_connections 6263004 STAT connection_structures 148 STAT cmd_get 1925983531 STAT cmd_set 615722800 STAT get_hits 1334407705 STAT get_misses 591575826 STAT evictions 7125864 STAT bytes_read 454794886199 STAT bytes_written 176758890326 STAT limit_maxbytes 2147483648 STAT threads 4 END
我无法理解为什么
~ $echo stats | nc -vv 10.251.170.80 11211 Connection to 10.251.170.80 11211 port [tcp/*] succeeded! ~ $
只是失败。
nc没有正确读取stdin的窍门吗?
CR / LF有什么问题?
我一直在尝试与input(-C)相关的每个nc命令行选项
~ $echo $SHELL /bin/bash ~ $bash --version GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu) Copyright (C) 2007 Free Software Foundation, Inc.
系统是fedora 9。
这对我使用nc.openbsd和nc.traditional debian的作品:
echo -e "stats\nquit" | nc 10.251.170.80 11211
你的netcat似乎是closures在标准input上的EOF连接,而不是等待输出..你可以尝试-q 1左右..
在标准input上的EOF之后-q秒,等待指定的秒数,然后退出。 如果秒是负面的,永远等待。
我倾向于使用如下的一行:
# (echo stats ; sleep 0.1) | netcat 10.251.170.80 11211
这似乎保持连接打开足够长的时间来得到答复。
没有新行发送?
那么尝试一下:〜$ echo -e'stats \ n'| nc -vv 10.251.170.80 11211
希望这可以帮助。
我用gearmand得到了同样的问题。 唯一的@ d5ve睡眠解决scheme适用于我:
(echo status; sleep 0.1) | nc -w1 locahost 4730