作者HuangTzHuan ()
看板FreeBSD
标题Re: [问题] 请教sed指令使用
时间Thu Jun 2 17:31:34 2011
※ 引述《lupin513 (萤幕,你不要走~~)》之铭言:
: 请教各位大大,
: 最近自家的SERVER一直被攻击,
: 想统计一下,并且整理资料,
: 在网路上看到这篇文章。
: http://chejen-l.blogspot.com/2011_05_01_archive.html
: grep 'login error' /var/log/openwebmail.log > auth_error.log
: sed ' s/^.* (\[0-9]*\.[0-9]*.\[0-9]*\.[0-9]*\).*/\1/g 'auth_error.log > ip_list.txt
^^ ^^
错误讯息抱怨括号没有成对,至少要改成这样,语法才是对的:
s/^.*\(\[0-9]*\.[0-9]*.\[0-9]*\.[0-9]*\).*/\1/g
不过这样是抓不到 ip 的 (至少我在 FreeBSD 9-current 上测是抓不到)
我建议改成这样:
sed 's/^.*(\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)).*/\1/' auth_error.log ...
: sort ip_list.txt > sort_ip_list.txt
: uniq -c sort_ip_list.txt
: 但是在我的FreeBSD中,第二行指令一直无法成功。
: 显示的错误讯息为:sed: 1: "s/^.* ([0-9]*\.[0-9]*.\ ...": RE error: parentheses not balanced
: 不知道是我的系统问题,还是我复制的指令有问题呢?
: 我的FreeBSD 是6.1,暂时没打算升级,请大大指导,谢谢。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.30.49
※ 编辑: HuangTzHuan 来自: 140.112.30.49 (06/02 17:33)