On Apr 21, "Jorge A. Jiles" wrote:
> Flow-tool V 0.66 Solaris
>
> Is there a way to concatenate files (flow-cat) over different days???
> Let's say I want to display stats from April 18-2004 22:30:00 until April
> 20-2004 07:00:00
>
> One way would be to move all appropriate flow-tools data files to a temp
> directory and then run flow-stat on this directory, but I don't like the
> idea of moving files since it takes times and space.
>
> In the flow-cat man pages it shows how to control start and end time (-t,
> -T) but does not say anything about start/end dates.
>
> Any help is appreciated.
>
> Thanks.
I wrote a script that tries to do this.
Are you using flow-capture with a non-zero nesting level? If so, this
won't work.
Let me know if it works for you.
Mike
#!/usr/bin/perl -w
use strict;
#Mike Hunter
#19 Dec 2002
#flow-cat a range of flows specified by date and time
use Getopt::Long;
my $debug;
my $start_date;
my $end_date;
my $start_time;
my $end_time;
my $pre_str = "ft-v05.";
my @flowdirs = qw( MY_FLOW_DIRECTORIES_HERE );
my $print;
my $flow_cat_exe = "FULL_PATH_TO_FLOW_CAT";
GetOptions("start-date|sd=s", \$start_date, "end-date|ed=s", \$end_date,
"start-time|st=s", \$start_time, "end-time|et=s", \$end_time,
"print", \$print);
if (not ((defined $start_time) && (defined $end_time)))
{
usage();
die "Missing time argument";
}
if (not ((defined $end_date) && (defined $start_date)))
{
usage();
die "Missing date argument";
}
#date format yyyy-mm-dd
#time format hh:mm (MILITARY)
my ($start_hour, $start_minute) = split /:/, $start_time;
my ($end_hour, $end_minute) = split /:/, $end_time;
if (($start_hour < 0) or ($start_hour > 23) or ($start_minute < 0 ) or
($start_minute >59) or ($end_hour < 0) or ($end_hour > 23) or
($end_minute < 0) or ($end_minute > 59))
{
die "improper time specification!";
}
my $flat_start_time = $start_hour.$start_minute."00";
my $flat_end_time = $end_hour.$end_minute."00";
my @start_stuff = split /-/, $start_date;
my @end_stuff = split /-/, $end_date;
if ((length $start_stuff[1] == 1 ) or (length $end_stuff[1] == 1) or
(length $start_stuff[2] == 1 ) or (length $end_stuff[2] == 1))
{
die "please specify two digit day and month!";
}
my $flat_start_date = $start_date;
$flat_start_date =~ s/-//g;
my $flat_end_date = $end_date;
$flat_end_date =~ s/-//g;
die "Date input range error" if ($flat_end_date < $flat_start_date);
die "Time input range error" if (($flat_end_date == $flat_start_date) and
($flat_end_time < $flat_start_time));
#Mon Dec 2 11:57:15 PST 2002
my $days_ahead = 0;
my $processed_date = "";
my ($start_year, $start_month, $start_day) = split /-/, $start_date;
my $start_dnt= $start_date.".".$flat_start_time."00";
my $end_dnt= $end_date.".".$flat_end_time."00";
my @dates;
my @flow_files;
my @final_flow_files;
while ($processed_date ne $end_date)
{
#my $date_cmd_str = "date -j -v".$start_year."y -v".$start_month.
#"m -v".$start_day."d -v".$start_hour."H -v".$start_minute.
#"M -v0S -v+".$days_ahead."d \"+%Y-%m-%d.%H%M%S\"";
my $date_cmd_str = "date -j -v".$start_year."y -v".$start_month.
"m -v".$start_day."d -v+".$days_ahead."d \"+%Y-%m-%d\"";
$processed_date = `$date_cmd_str`;
chomp $processed_date;
push @dates, $processed_date;
#print "$processed_date ne $end_dnt\n";
$days_ahead++;
}
foreach my $date (@dates)
{
foreach my $dir (@flowdirs)
{
push @flow_files, `ls $dir/$pre_str$date*`;
}
}
chomp @flow_files; #each \n is gone
#prune out the bad ones
foreach my $filename (@flow_files)
{
my ($f_date, $f_time) = (split /\./, $filename)[-2,-1];
$f_time =~ s/-.*$//;
my $flat_f_date = $f_date;
$flat_f_date =~ s/-//g;
#print "match: $filename f_date f_time sd ed st et\n";
#print "$f_date $f_time\n$start_date $end_date\n$start_time".
#" $end_time\n";
if ( ($flat_start_date == $flat_end_date) and
($flat_end_date == $flat_f_date))
{
if (&range ($flat_start_time, $f_time, $flat_end_time))
{
push @final_flow_files, $filename;
}
#else {print "no push in start==end case";}
}
elsif ($flat_start_date == $flat_f_date)
{
if (&range ($flat_start_time, $f_time, 240000))
{
push @final_flow_files, $filename;
}
#else {print "no push in start_date case";}
}
elsif ($flat_end_date == $flat_f_date)
{
if (&range (0, $f_time, $flat_end_time))
{
push @final_flow_files, $filename;
}
#else {print "no push in end_date case";}
}
elsif ( &range($flat_start_date, $flat_f_date, $flat_end_date) )
{
push @final_flow_files, $filename;
}
#else {print "no push for $filename!\n";}
##if it's in the date range
#if (($flat_f_date >= $flat_start_date) and
#($flat_f_date <= $flat_end_date) )
#{
##if it's not a border case, just push
#if (($flat_f_date > $flat_start_date) and
#($flat_f_date < $flat_end_date) )
#{
#print "in-between DATE push\n";
#push @final_flow_files, $filename;
#}
#elsif ( ($flat_start_date == $f_date) and
#($flat_start_time <= $f_time))
#{
##otherwise if it is a border case, check the actual time
#print "first day good time push\n";
#push @final_flow_files, $filename;
#}
#($flat_end_time >= $f_time))
#else {print "no push!\n";}
#}
}
sub range
{
my $a = shift;
my $b = shift;
my $c = shift;
$debug and print "$a $b $c\n";
if (($a <= $b) and ($b < $c))
{
return 1;
}
else
{
return 0;
}
}
my $flows_str = join " ", @final_flow_files;
if ($print)
{
print $flows_str;
}
else
{
exec("$flow_cat_exe $flows_str");
}
#print join "\n", @final_flow_files;
sub usage
{
print <<uSaGe
Usage: flow-range -sd YYYY-MM-DD -ed YYYY-MM-DD -st HH:MM -et HH:MM
a.k.a. -start-date YYYY-MM-DD -end-date ... -start-time ... -end-time ...
You must specify all four parameters!
uSaGe
}
_______________________________________________
Flow-tools mailing list
[EMAIL PROTECTED]
http://mailman.splintered.net/mailman/listinfo/flow-tools