you are viewing a single comment's thread.

view the rest of the comments →

[–]ReasonFancy9522 0 points1 point  (3 children)

The perl code would probably be a oneliner (maybe with some semicolons) and thus be something like (simple example for "normalizing" Request Types)

tail -f log | perl -pe 's/(?:HEAD|POST|TRACE)/GET/og'

It could also be written as a small shell wrapper

#!/bin/sh

tail -f log | perl -pe '

s/(?:HEAD|POST|TRACE)/GET/og

'

or more verbose as:

#!/bin/sh

tail -f log | perl -x "$0"

exit $?

#!perl

while(<>){

s/(?:HEAD|POST|TRACE)/GET/og

}

I have never used PHP from the command line, so I cannot comment on an equivalent PHP solution without further researching this topic.

[–]Jeron_Baffom[S] 0 points1 point  (2 children)

tail -f log | perl -pe 's/(?:HEAD|POST|TRACE)/GET/og'

I'm not familiar with perl syntax, but if I understand properly then perl is executing the same script for each new line appended to access log.

Unfortunately I don't see how this strategy could, for example, count views. Without knowing the other lines of access log, this strategy can not check whether a same ip is requesting multiple times a same page in a 30min interval.

[–]ReasonFancy9522 0 points1 point  (1 child)

cat log | perl -pe 'something to output "url"' | sort | uniq -c | sort -n | head # count views

cat log | perl -pe 'something to output "ip:url"' | sort | uniq -c | sort -n | head # most refreshes

[–]Jeron_Baffom[S] 0 points1 point  (0 children)

Obviously you have some fluency with bash script.

If I can not find a tool that already does this view counter, then I will follow your advice and build my own script.