linux – Netcat命令行问题

前端之家收集整理的这篇文章主要介绍了linux – Netcat命令行问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用netcat从memcached服务器收集统计信息.
  1. ~ $nc 10.251.170.80 11211
  2. stats
  3. STAT pid 27508
  4. STAT uptime 7940345
  5. STAT time 1262949310
  6. STAT version 1.2.4
  7. STAT pointer_size 64
  8. STAT rusage_user 1389.962693
  9. STAT rusage_system 4857.247586
  10. STAT curr_items 9154565
  11. STAT total_items 615722800
  12. STAT bytes 1994844049
  13. STAT curr_connections 62
  14. STAT total_connections 6263004
  15. STAT connection_structures 148
  16. STAT cmd_get 1925983531
  17. STAT cmd_set 615722800
  18. STAT get_hits 1334407705
  19. STAT get_misses 591575826
  20. STAT evictions 7125864
  21. STAT bytes_read 454794886199
  22. STAT bytes_written 176758890326
  23. STAT limit_maxbytes 2147483648
  24. STAT threads 4
  25. END

我无法理解为什么

  1. ~ $echo stats | nc -vv 10.251.170.80 11211
  2. Connection to 10.251.170.80 11211 port [tcp/*] succeeded!
  3. ~ $

只是失败了.

有没有一个技巧nc没有正确读取标准输入?

CR / LF出了什么问题?

我一直在尝试与输入(-C)相关的每个nc命令行选项

  1. ~ $echo $SHELL
  2. /bin/bash
  3. ~ $bash --version
  4. GNU bash,version 3.2.33(1)-release (i386-redhat-linux-gnu)
  5. Copyright (C) 2007 Free Software Foundation,Inc.

该系统是fedora 9.

解决方法

这对我使用nc.openbsd和nc.traditional都适用于debian:
  1. echo -e "stats\nquit" | nc 10.251.170.80 11211

您的netcat似乎正在关闭stdin上的EOF连接而不是等待输出..
你可以尝试-q 1左右..

-q seconds after EOF on stdin,wait the specified number of seconds and then quit. If seconds is negative,wait forever.

猜你在找的Linux相关文章