Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- #error check
- if(@ARGV != 1)
- {
- print STDERR "ERROR:\t This program will only work with one commandline arguement that is a file\n";
- exit;
- }
- #print the first 2 lines
- print "host accessing server\t: ipaddress\t: accesses : bytes transferred\n---------------------------------------------------------------------------\n";
- #Variables
- my ($p_host, $k_ip, $cnt, $host, $ip, $acc, $byte, $line, $i, %h_byte, %h_access, %h_ip ,$temp, %rows,@temp, @data);
- #skip first two lines
- <> for 1 .. 2;
- #reading in from logfile and filling hash table with data
- while($line = <>) #splitting logfile into lines
- {
- chomp $line; #grabs the line
- @data = split (' ',$line); #parses the line
- $host = $data[1];
- $h_ip {$host} = $data[0];
- $h_byte {$host} = $data[2];
- if($h_ip{$host})
- {
- $h_access{$host}++;
- }
- else
- {
- $h_access{$host} = 1;
- }
- }
- #display them as a format
- #while(my ($k_ip,$ip) = each(%h_ip))
- #foreach $k_ip (sort(keys(%h_ip)));
- while(my ($k_ip,$ip) = each(%h_ip))
- {
- my ($k_byte,$byte) = each(%h_byte);
- my ($k_access,$acc) = each(%h_access);
- format STDOUT =
- @<<<<<<<<<<<<<<<<<<<<<< : @<<<<<<<<<<<< : @>>>>>>> : @>>>>>>>>>>>>>>>>
- $k_ip,$ip,$acc,$byte
- .
- write;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement