c/src/Makefile: Create and use `INSTALL_TARGETS`
[sunny256-utils.git] / ep-pause
blob18dad5cf364211de2a0cd31c7443a53c80cba75c
1 #!/usr/bin/env perl
3 #=======================================================================
4 # ep-pause
5 # File ID: 1f845a80-5d39-11df-95dd-90e6ba3022ac
6 # Finner pauser mellom datoer på epoch-format.
8 # Character set: UTF-8
9 # ©opyleft 2004– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License, see end of file for legal stuff.
11 #=======================================================================
13 use strict;
14 use warnings;
15 use Time::Local;
17 $| = 1;
19 use Getopt::Std;
20 our ($opt_h, $opt_l, $opt_s) =
21 ( 0, 1, 0);
22 getopts('hl:s') || die("Option error. Use -h for help.\n");
24 my $VERSION = "0.0";
26 our $progname = $0;
27 $progname =~ s#^.*/(.*?)$#$1#;
29 $opt_h && usage(0);
31 my $last_sec = 0;
32 my $d_sep = "-";
33 my $dt_sep = "T";
34 my $t_sep = ":";
36 while (<>) {
37 if (/^.*?(\d+).*?$/) {
38 my $Secs = $1;
39 my $Pause = $Secs - $last_sec;
40 if ($last_sec && ($Pause >= $opt_l)) {
41 if ($opt_s) {
42 my @TA = gmtime($last_sec);
43 printf("%04u$d_sep%02u$d_sep%02u$dt_sep%02u$t_sep%02u$t_sep%02uZ\t$Pause\n",
44 $TA[5]+1900, $TA[4]+1, $TA[3], $TA[2], $TA[1], $TA[0]);
45 } else {
46 printf(
47 "%u-%u\t%u\t%s\n",
48 $last_sec, $Secs,
49 $Pause, sec_to_hms($Pause)
53 $last_sec = $Secs;
54 } else {
55 print(STDERR "Ukjent linje $.\n");
59 sub sec_to_hms {
60 # {{{
61 my $secs = shift;
62 my ($Day, $Hour, $Min, $Sec) = (0, 0, 0, 0);
64 $Day = int($secs/86400);
65 $secs -= $Day*86400;
67 $Hour = int($secs/3600);
68 $secs -= $Hour * 3600;
70 $Min = int($secs/60);
71 $secs -= $Min * 60;
73 $Sec = $secs;
75 return(($Day ? "$Day:" : "") . sprintf("%02u:%02u:%02u", $Hour, $Min, $Sec));
76 # }}}
77 } # Tidsperiode()
79 sub usage {
80 # Send the help message to stdout {{{
81 my $Retval = shift;
82 print(<<END);
83 $progname v$VERSION
85 Usage: $progname [options] [file [...]]
87 Scans Apache access logs and prints out time periods with no connections.
89 Options:
91 -h Print this help.
92 -l x Show only pauses longer than x seconds.
94 END
95 exit($Retval);
96 # }}}
99 __END__
101 # Plain Old Documentation (POD) {{{
103 =pod
105 =head1 NAME
107 ep-pause — find pauses in Apache logs
109 =head1 SYNOPSIS
111 ep-pause [options] [file [...]]
113 =head1 DESCRIPTION
117 =head1 OPTIONS
119 =over 4
121 =item B<-h>
123 Print a brief help summary.
125 =item B<-l> x
127 Only list pauses longer than I<x> seconds.
129 =back
131 =head1 BUGS
135 =head1 AUTHOR
137 Made by Øyvind A. Holm S<E<lt>sunny _AT_ sunbase.orgE<gt>>.
139 =head1 COPYRIGHT
141 Copyleft © Øyvind A. Holm &lt;sunny@sunbase.org&gt;
142 This is free software; see the file F<COPYING> for legalese stuff.
144 =head1 LICENCE
146 This program is free software; you can redistribute it and/or modify it
147 under the terms of the GNU General Public License as published by the
148 Free Software Foundation; either version 2 of the License, or (at your
149 option) any later version.
151 This program is distributed in the hope that it will be useful, but
152 WITHOUT ANY WARRANTY; without even the implied warranty of
153 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
154 See the GNU General Public License for more details.
156 You should have received a copy of the GNU General Public License along
157 with this program; if not, write to the Free Software Foundation, Inc.,
158 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
160 =head1 SEE ALSO
162 =cut
164 # }}}
166 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
167 # End of file ep-pause