Simple command to “watch” the webserver access log
April 2nd, 2010 | by Sajal Kayan |I am often curious as to what bots are going on my site at any given moment. So much so that I devote one terminal tab to running this script.
save the following as say bot.sh and make it executable :-
-
#!/bin/bash
-
watch "grep $1 /path/to/access.log | tail -15"
note: the number after tail can be adjusted depending on your terminal size…
Run it on the server as :-
-
[user@server ~]# ./bot.sh Googlebot
OR
-
[user@server ~]# ./bot.sh msnbot
OR
-
[user@server ~]# ./bot.sh <suspicious ip address>
and so on….
UPDATE: Better alternative by willwill. Save as bot.sh:-
-
#!/bin/bash
-
watch "tail -f /path/to/access.log | grep $1"


4 Responses to “Simple command to “watch” the webserver access log”
By willwill on Apr 2, 2010 | Reply
Why not
tail -f /var/log/apache2/access.log | grep $1
as tail -f will write out new line immedialy, while watch will run specified command periodically.
By Sajal Kayan on Apr 2, 2010 | Reply
@willwill interesting. tail -f works much better and im sure will have lesser load since its only frepping new lines…
earlier i tried tail -f after grep and didnt workout so well… but yr command works perfectly.
By todd on Apr 5, 2010 | Reply
have you used ntop?
By Mark C on Aug 5, 2010 | Reply
Sajal, are you still running this script or have you found a new one that gives a little more data?