#!/usr/bin/env perl

use warnings;
use strict;
use IPC::Cmd 0.36 qw( can_run run );
use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
use Pod::Usage qw( pod2usage );

my $start = undef;
my $end = undef;
my $product = undef;

GetOptions( 
        'start|s=s' => \$start,
        'end|e=s' => \$end,
        'product|p=s' => \$product,
        )  or pod2usage( 2 );

pod2usage(
        -msg => "\n   Required options:\n\n".
        "--start <jobStartNumber> [--end <jobEndNumber>]\n".
        "--product <datastoreProduct>\n",
        -exitval => 3
        ) unless
defined $product and
defined $start;


if (!defined $end) {$end = 1000000;}

my $i;

for ($i=$start; $i<$end+1; $i++) {

    my $job = sprintf("J%06d", $i);
    my $command  = "dsreg --del $job --product $product";

    run(command => $command, verbose => 1);
}
