Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $access_log = $ARGV[0] || '/var/log/apache2/access.log';
- my %user_agents = ();
- if (open FILE,'<',"$access_log") {
- while (<FILE>) {
- my $line = $_;
- if (my ($ua) = ($line =~ /\"([^"]+)\"$/)) {
- $user_agents{$ua}++;
- }
- }
- close FILE;
- } else {
- print STDERR "could not open \'$access_log\': $!\n";
- exit;
- }
- my @sorted = sort { $user_agents{$b} <=> $user_agents{$a} } keys %user_agents;
- foreach my $user_agent (@sorted) {
- print "$user_agent: $user_agents{$user_agent}\n";
- }
Add Comment
Please, Sign In to add comment