diff --git a/scripts/remove_session b/scripts/remove_session index f90002e..7bc1078 100755 --- a/scripts/remove_session +++ b/scripts/remove_session @@ -9,6 +9,7 @@ use strict; use Simba::CA; use Bit::Vector::Judy; +use Getopt::Long; $| = 1; @@ -18,6 +19,24 @@ my $ca = Simba::CA->new({ my $dbh = $ca->{dbh}; +my %opt; +GetOptions( + \%opt, + "age=s"); + +if ($opt{age}) { + my ($num, $unit) = $opt{age} =~ /(\d(?:.\d+)?)(y|m|w|d)/; + my $scale = { y => 365 * 86400, + m => 30 * 86400, + w => 7 * 86400, + d => 1 * 86400 }->{$unit}; + die "unknown time unit $unit" unless $scale; + my $expired_sessions + = $dbh->selectcol_arrayref("select id from sessions where start_date < ? order by id", + {}, + time() - $num * $scale); + push @ARGV, @$expired_sessions; +} for my $session (@ARGV) { print "deleting instances of session $session\n"; my $n_instances = $dbh->do("delete from instances where session=?", {}, $session);