为什么我不建议把数据放入db中呢?优点不言自明,我们可以通过sql语句很容易把数据拿出来。
缺点呢?首先就是我们不能把什么东西都往db里放?
cat netstat.txt Proto Recv-Q Send-Q Local-Address Foreign-Address State tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN tcp 1 1 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN tcp 0 0 yuedu.com:80 124.205.5.146:18245 TIME_WAIT tcp 0 0 yuedu.com:80 61.140.101.185:37538 FIN_WAIT2 tcp 0 0 yuedu.com:80 110.194.134.189:1032 ESTABLISHED tcp 0 0 yuedu.com:80 123.169.124.111:49809 ESTABLISHED tcp 0 0 yuedu.com:80 116.234.127.77:11502 FIN_WAIT2 tcp 0 0 yuedu.com:80 123.169.124.111:49829 ESTABLISHED tcp 0 0 yuedu.com:80 183.60.215.36:36970 TIME_WAIT tcp 0 4166 yuedu.com:80 61.148.242.38:30901 ESTABLISHED tcp 0 1 yuedu.com:80 124.152.181.209:26825 FIN_WAIT1 tcp 0 0 yuedu.com:80 110.194.134.189:4796 ESTABLISHED tcp 0 0 yuedu.com:80 183.60.212.163:51082 TIME_WAIT tcp 0 1 yuedu.com:80 208.115.113.92:50601 LAST_ACK tcp 0 0 yuedu.com:80 123.169.124.111:49840 ESTABLISHED tcp 0 0 yuedu.com:80 117.136.20.85:50025 FIN_WAIT2 tcp 0 0 :::22 :::* LISTEN
查询所有tcp中,接受队列非0的网络包。
localhost:zhoubc Guest$ awk ‘$1 =="tcp" && $2 > 0‘ netstat.txt tcp 1 1 0.0.0.0:80 0.0.0.0:* LISTEN
打印出来的内容,我们不知所云。如果把第一行打出来,就一目了然了。这时候我们要用到awk的全局常量(如果想知道AWK的全局常量,我们可以往下看,附录,我把常用的罗列出来了)NR。
localhost:zhoubc Guest$ awk ‘NR==1 || $1 =="tcp" && $2 > 0‘ netstat.txt Proto Recv-Q Send-Q Local-Address Foreign-Address State tcp 1 1 0.0.0.0:80 0.0.0.0:* LISTEN
看爽了是不是?
原文:http://www.cnblogs.com/baochuan/p/3833130.html