Advertisement
devinteske

last_log_line.cgi

Nov 18th, 2019
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.44 KB | None | 0 0
  1. #!/usr/bin/perl
  2. ############################################################ IDENT(1)
  3. #
  4. # $Title: CGI to get last line of logfile $
  5. # $Copyright: 2017-2019 Devin Teske. All rights reserved. $
  6. # $FrauBSD$
  7. #
  8. ############################################################ INFORMATION
  9. #
  10. # For driving Vizceral.
  11. #
  12. ############################################################ INCLUDES
  13.  
  14. use strict;
  15. use warnings;
  16. use CGI;
  17. use File::ReadBackwards;
  18.  
  19. ############################################################ CONFIGURATION
  20.  
  21. (my $script = $ENV{SCRIPT_NAME} || $0) =~ s{^.*/([^/]+)\.cgi$}{$1}i;
  22. my $LOGFILE = "/var/log/$script.log";
  23.  
  24. ############################################################ GLOBALS
  25.  
  26. #
  27. # mod_perl/CGI
  28. #
  29. our $r    = $ENV{MOD_PERL} ? shift : undef;
  30. our $html = $ENV{REQUEST_METHOD} ? 1 : 0;
  31. our $cgi  = new CGI;
  32.  
  33. $| = 1 if $html; # Disable output buffering to browser(s)
  34.  
  35. ############################################################ FUNCTIONS
  36.        
  37. sub lastline
  38. {      
  39.         my ($file) = @_;
  40.         return +( File::ReadBackwards->new($file)
  41.                 or die "$file: $!" )->readline();
  42. }
  43.  
  44. ############################################################ MAIN
  45.  
  46. print $cgi->header("application/javascript");
  47. print &lastline($LOGFILE);
  48. exit 0;
  49.  
  50. ################################################################################
  51. # END
  52. ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement