上网查了很久都没有我想要的结果,于是我决定自己动手来实现我想要的效果,离我期望的还差那么一点点但还是比较满意的。系统环境是Centos5.2的,既然需要的squid日志的提取,相信squid代理的配置应该都没有问题,在这里就不多说了。在此提供两种方法:
方法—:
需要安装软件包,newsyslog-1.8.tar.gz自己可以从网上下载.
1.安装步骤:
#./configure #make #make install #此步安装完成后newsyslog应道安装在以下路径,安装这步可能会提示你创建文件或目录如下: #mkdir/usr/local/man/ #新建一个man8文件
2.修改与配置文件 newsyslog.conf
#vim /usr/local/etc/newsyslog.conf set squid_logpath = /var/log/squid/access.log #squid日志的路径下面就不过多的解释 set squid_log = /var/log/squid/access.log set date_squid_log = /var/log/squid/access%Y%M%D.log SQUID{ restart: run/usr/sbin/squid -k rotate log:SQUID squid_log squid squid 644 archive: SQUIDdate_squid_log 0
3.建立定制任务
执行newsyslog即可也可以将此任务添加到crontab文件里
00 23 * * * /usr/local/sbin/newsyslog
方法二:
那就要编写一个shell了
Shell的内容如下:shell的存放/var/log/squid/extract-today.sh
#!/bin/bash date> today-string-file #$grepLine="perl-pe 's/[\d\.]+/localtime($&)/e' access.log|grep " cattoday-string-file | while read LINE ; do field1=`echo$LINE|awk '{print $1}'` field2=`echo$LINE|awk '{print $2}'` field3=`echo$LINE|awk '{print $3}'` field4=`echo$LINE|awk '{print $4}'` field5=`echo$LINE|awk '{print $5}'` field6=`echo$LINE|awk '{print $6}'` echo$field1 echo$field2 echo$field3 echo$field4 echo$field5 echo$field6 #pattern=$field1""$field2" "$field3 #echo$pattern LEN=`exprlength "$field3"` echo$LEN if[ $LEN -eq 1 ]; then #pattern=$field1""$field2" "$field3 echo"perl -pe 's/[\d\.]+/localtime($&)/e' access.log|grep '$field1 $field2$field3'|grep '$field6'">extrToday bashextrToday > Today-Squid-Accessed-Log fi if[ $LEN -eq 2 ]; then #pattern=$field1""$field2" "$field3 echo"perl -pe 's/[\d\.]+/localtime($&)/e' access.log|grep '$field1 $field2$field3'|grep '$field6'">extrToday bashextrToday > Today-Squid-Accessed-Log fi done
保存退出,执行刚建立的shell你就可以查看了Today-Squid-Accessed-Log 文件了!
转载于:https://blog.51cto.com/lj119/135106