Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.21 KB | None | 0 0
  1.  
  2. use strict;
  3.  
  4. #error check
  5. if(@ARGV != 1)
  6. {
  7. print STDERR "ERROR:\t This program will only work with one commandline arguement that is a file\n";
  8. exit;
  9. }
  10. #print the first 2 lines
  11. print "host accessing server\t: ipaddress\t: accesses : bytes transferred\n---------------------------------------------------------------------------\n";
  12.  
  13. #Variables
  14. my ($p_host, $k_ip, $cnt, $host, $ip, $acc, $byte, $line, $i, %h_byte, %h_access, %h_ip ,$temp, %rows,@temp, @data);
  15.  
  16. #skip first two lines
  17. <> for 1 .. 2;
  18.  
  19. #reading in from logfile and filling hash table with data
  20. while($line = <>) #splitting logfile into lines
  21. {
  22.  
  23. chomp $line;                    #grabs the line
  24. @data = split (' ',$line);      #parses the line
  25.  
  26. $host = $data[1];
  27. $h_ip {$host} = $data[0];
  28. $h_byte {$host} = $data[2];
  29. if($h_ip{$host})
  30. {
  31.  $h_access{$host}++;
  32. }
  33. else
  34. {
  35.  $h_access{$host} = 1;
  36. }
  37. }
  38.  
  39. #display them as a format
  40. #while(my ($k_ip,$ip) = each(%h_ip))
  41. #foreach $k_ip (sort(keys(%h_ip)));
  42.  
  43. while(my ($k_ip,$ip) = each(%h_ip))
  44. {
  45. my ($k_byte,$byte) = each(%h_byte);
  46. my ($k_access,$acc) = each(%h_access);
  47.  
  48. format STDOUT =
  49. @<<<<<<<<<<<<<<<<<<<<<< : @<<<<<<<<<<<< : @>>>>>>> : @>>>>>>>>>>>>>>>>
  50. $k_ip,$ip,$acc,$byte
  51. .
  52.  
  53. write;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement