-
Notifications
You must be signed in to change notification settings - Fork 0
/
count-log-lines.pl
executable file
·48 lines (42 loc) · 1.15 KB
/
count-log-lines.pl
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
#!/usr/bin/perl
#
# Count Log Lines v1.0 - David Mcanulty 2013 - [email protected]
# Watches a logfile and prints the number of lines added to it per 'delay' cycle
#
# count-log filename [delay]
my $start_time=time();
my $start = localtime();
$num_args = $#ARGV + 1;
if ($num_args == 0) {
print "\nWatches a logfile and prints the number of lines added to it per 'delay' cycle\n";
print "\nUsage: $0 filename [delay]\n";
exit;
}
$file=$ARGV[0];
if (! -e $file) {
die "Sorry file: ($file) does not exist\n"
}
if ($num_args == 2) {
$delay = $ARGV[1];
if ((! $delay >= 1) || ($delay =~ m/\D/g)) {
die "Sorry, delay must be a positive integer, you provided: ($delay)\n"
}
}else{
$delay=1;
}
$previous_lines = `wc -l $file`; #seed
$line=999;
while (1) {
if ($line > 200){
$line=0;
$current_time= localtime();
print "\nStarted at: \t $start\n";
print "current time: \t $current_time\n";
print "Lines added to $file in the last $delay seconds: ";
}
sleep $delay;
$current_lines = `wc -l $file`;
print $current_lines - $previous_lines, " ";
$previous_lines = $current_lines;
$line++;
}