-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogroller
More file actions
executable file
·89 lines (69 loc) · 2.28 KB
/
logroller
File metadata and controls
executable file
·89 lines (69 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl
#simple tool to help manage log rollover for debugging
#just pipe output to this command, and it will handle saving the
#last F*L lines of data (F is the number of files, L is the number
#of lines per file)
#reasonable defaults exist for all options. Call help (-h or --help) for details
use warnings;
use strict;
use constant VERSION=>"this is the verion";
use Getopt::Long;
my($PROGNAME) = ($0 =~ m|([^/]+)$|);
use vars qw ( $help_requested $version_requested );
my $version='$Id: rolling-log,v 1.3 2012/12/31 17:00:06 washer Exp washer $'; #rcs id
my $version_requested;
my $tee = 0; #tee to stdout
my $showroll = 0; #show file rolling
my $fname="logroll".$$;
my $fcnt=10; #File Count
my $lpf=10000; #Lines Per File
my $cnt; #current line number in current output file
my $currentfname;
my $lognum=1;
my $ln; #current line number
my $fn; #current file number
Getopt::Long::Configure( 'auto_abbrev', 'bundling', 'ignore_case' );
GetOptions(
'o|output=s' => \$fname,
'f|fcnt=i' => \$fcnt,
'l|lines=i' => \$lpf,
'r|roll|?' => \$showroll,
't|tee|?' => \$tee,
'v|vesion|?' => \$version_requested,
'h|help|?' => \$help_requested,
) or $help_requested = 1;
if ($version_requested) {
print STDERR "$0: $version\n";
exit(0);
}
if ( $help_requested ){
print STDERR "\t-o|--output\t\tFilename (defaults to logroll)\n",
"\t-f|--fcnt\t\tNumber of files to save (defaults to 10)\n",
"\t-l|--lines\t\tLines per file (defaults to 10,000)\n",
"\t-t|--tee\t\t'Tee' to stdout\n",
"\t-r|--roll\t\tShow progress as each log file rolls over. Mostly for peace of mind that output is occurring\n",
"\t-h|--help\t\tThis help screen\n";
exit(0);
}
$currentfname=sprintf "%s-%09.9d",$fname,$lognum;
open( OUT, ">", $currentfname ) or die "uname to open $currentfname";
while(<>){
print OUT $_;
print if $tee;
$cnt++;
if ($cnt >= $lpf){
$cnt=0;
close OUT;
$fn++;
$currentfname=sprintf "%s-%09.9d",$fname,$lognum;
open( OUT, ">", $currentfname ) or die "uname to open $currentfname";
print STDERR "opening new file $currentfname " if $showroll;
if($lognum-$fcnt > 0){
$currentfname=sprintf "%s-%09.9d",$fname,$lognum-$fcnt;
unlink $currentfname;
print STDERR "removing old file $currentfname" if $showroll;
}
$lognum++;
print "\n" if $showroll;
}
}