grep命令抓取问题

  1. [root@localhost python]# nc -v -z -w2 192.168.1.203 1-21
  2. nc: connect to 192.168.1.203 port 13 (tcp) failed: Connection refused
  3. nc: connect to 192.168.1.203 port 14 (tcp) failed: Connection refused
  4. nc: connect to 192.168.1.203 port 15 (tcp) failed: Connection refused
  5. nc: connect to 192.168.1.203 port 16 (tcp) failed: Connection refused
  6. nc: connect to 192.168.1.203 port 17 (tcp) failed: Connection refused
  7. nc: connect to 192.168.1.203 port 18 (tcp) failed: Connection refused
  8. nc: connect to 192.168.1.203 port 19 (tcp) failed: Connection refused
  9. nc: connect to 192.168.1.203 port 20 (tcp) failed: Connection refused
  10. Connection to 192.168.1.203 21 port [tcp/ftp] succeeded!
复制代码
如图所示!使用命令输出成功和失败两种信息!
我只想让它显示成功信息用grep抓关键字 'succeeded!'
结果是:跟上图一样!
  1. [code][root@localhost python]# nc -v -z -w2 192.168.1.203 1-21|grep 'succeeded!'
  2. nc: connect to 192.168.1.203 port 13 (tcp) failed: Connection refused
  3. nc: connect to 192.168.1.203 port 14 (tcp) failed: Connection refused
  4. nc: connect to 192.168.1.203 port 15 (tcp) failed: Connection refused
  5. nc: connect to 192.168.1.203 port 16 (tcp) failed: Connection refused
  6. nc: connect to 192.168.1.203 port 17 (tcp) failed: Connection refused
  7. nc: connect to 192.168.1.203 port 18 (tcp) failed: Connection refused
  8. nc: connect to 192.168.1.203 port 19 (tcp) failed: Connection refused
  9. nc: connect to 192.168.1.203 port 20 (tcp) failed: Connection refused
  10. Connection to 192.168.1.203 21 port [tcp/ftp] succeeded!
复制代码
[/code]
反过来选择,我忽略refused
结果:还是一样!真是奇了个怪了。
  1. [root@localhost python]# nc -v -z -w2 192.168.1.203 1-21|grep -v 'refused'
  2. nc: connect to 192.168.1.203 port 1 (tcp) failed: Connection refused
  3. nc: connect to 192.168.1.203 port 2 (tcp) failed: Connection refused
  4. nc: connect to 192.168.1.203 port 3 (tcp) failed: Connection refused
  5. nc: connect to 192.168.1.203 port 4 (tcp) failed: Connection refused
  6. nc: connect to 192.168.1.203 port 5 (tcp) failed: Connection refused
  7. nc: connect to 192.168.1.203 port 6 (tcp) failed: Connection refused
  8. nc: connect to 192.168.1.203 port 7 (tcp) failed: Connection refused
  9. nc: connect to 192.168.1.203 port 8 (tcp) failed: Connection refused
  10. Connection to 192.168.1.203 21 port [tcp/ftp] succeeded!
复制代码

作者: skyxue215   发布时间: 2011-03-09

那个是 “标准错误输出”stderr 输出的。

作者: jerryjzm   发布时间: 2011-03-09

回复 jerryjzm


    谢了兄弟

作者: skyxue215   发布时间: 2011-03-09