[Bash] Jak przerobić skrypt aby działał z error.logiem?


(Saver) #1

Witam, mam problem z skryptem bash którego teraz bardzo potrzebuje, skrypt ma wyświetlić adresy ip i ilość razy ile ten adres ip wszedł na stronę.

Skrypt:

FILE=/var/log/apache2/error.log;

 for ip in `cat $FILE |cut -d ' ' -f 1 |sort |uniq`;

 do { COUNT=`grep ^$ip $FILE |wc -l`;

 if [["$COUNT" -gt "500"]]; then echo "$COUNT: $ip";

 fi }; done

z access.log działa pięknie:

6975: 124.115.3.33

5648: 124.115.5.169

1514: 66.219.73.236

1451: 74.204.11.20

z error.logiem nie radzi sobie:

root@aaa:~# ./countIP

grep: Niesparowane [ lub [^

grep: Niesparowane [ lub [^

grep: Niesparowane [ lub [^

grep: Niesparowane [ lub [^

wzór error.logu:

[Wed Jan 02 07:39:37 2013] [error] [client 220.250.52.66] script '/var/403/viewtopic.php' not found or unable to stat, referer: http://www.buyXXXXede.com

[Wed Jan 02 07:41:48 2013] [error] [client 220.250.52.66] script '/var/403/viewtopic.php' not found or unable to stat, referer: http://www.beXXXXone.com

[Wed Jan 02 07:41:51 2013] [error] [client 58.22.123.98] script '/var/403/profile.php' not found or unable to stat, referer: http://www.waXXXXXhop.co.uk

i access.logu

2001:470:5052:0:224:1dff:feb3:537b - - [02/Jan/2013:07:47:18 +0100] "GET /wp-content/themes/bigfoot/includes/timthumb.php?src=http://itunix.eu/wp-content/uploads/2011/02/1297106282_easymoblog.png&h=200&w=200&zc=1 HTTP/1.1" 304 177 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20121231 Firefox/20.0"

2001:470:5052:0:224:1dff:feb3:537b - - [02/Jan/2013:07:47:18 +0100] "GET /wp-content/themes/bigfoot/includes/timthumb.php?src=http://itunix.eu/wp-content/uploads/2011/11/linux250x2501.jpg&h=200&w=200&zc=1 HTTP/1.1" 304 177 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20121231 Firefox/20.0"

2001:470:5052:0:224:1dff:feb3:537b - - [02/Jan/2013:07:47:20 +0100] "GET /wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css?ver=3.0.83c HTTP/1.1" 304 212 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20121231 Firefox/20.0"

Jak to można przerobić aby liczył adresy ip z error.logu?


(roobal) #2

Spróbuj tak.

#!/bin/bash