Veritas-bu

[Veritas-bu] list media by last written date

2003-01-25 10:20:35
Subject: [Veritas-bu] list media by last written date
From: trosamond AT uslec DOT com (Rosamond, Travis)
Date: Sat, 25 Jan 2003 10:20:35 -0500
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C2C485.4F4A4460
Content-Type: multipart/alternative;
        boundary="----_=_NextPart_001_01C2C485.4F4A4460"


------_=_NextPart_001_01C2C485.4F4A4460
Content-Type: text/plain;
        charset="iso-8859-1"

Here is a perl script I asked our perl guy to write to do what you/we are
requesting...  We use it for our weekly rotations.
 
Hope this is helpful...
-----Original Message-----




 It has two modes of operation, command line and interactive.

Command line format is:
./nb.pl <Start Date> <Start Time> <End Date> <End Time>

executed as:
./nb.pl  01/20/03 06:00 01/22/03 23:59

Notice that the time you enter does not have the seconds, it is only HH:MM,
the seconds are appended as :00 to the input.

To use it in automatic mode just type ./nb.pl and you are prompted through
all the required information.   A couple notes though, the time is checked
to make sure that the hours are valid and the minutes are valid and the date
is checked to make sure a valid month is entered and a valid number of days
for that month.  For example, you cannot say 02/30/03 it will give an
informational error and prompt for  the same info until the user gets it
right or <CTR>C is pressed.

What it does not check is the dates against each other.  It does not make
sure that the '-d' date or tim is earlier than the '-e' date or time.  Also,
the year is only checked to make sure it is two digits.  The value of the
year you enter is not checked at all.  Also the year is hardcoded with a
'20' prefix.  If you need this changed let me know.


------_=_NextPart_001_01C2C485.4F4A4460
Content-Type: text/html;
        charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE></TITLE>

<META content="MSHTML 6.00.2800.1126" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=098473114-25012003><FONT color=#0000ff>Here is a perl script I 
asked our perl guy to write to do what you/we are requesting...&nbsp; We use it 
for our weekly rotations.</FONT></SPAN></DIV>
<DIV><SPAN class=098473114-25012003><FONT 
color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=098473114-25012003><FONT color=#0000ff>Hope this is 
helpful...</FONT></SPAN></DIV>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
size=2>-----Original Message-----<BR><BR></FONT></DIV>
<P><FONT size=2><BR>&nbsp;It has two modes of operation, command line and 
interactive.<BR><BR>Command line format is:<BR><FONT color=#0000ff>./nb.pl 
&lt;Start Date&gt; &lt;Start Time&gt; &lt;End Date&gt; &lt;End 
Time&gt;</FONT><BR><BR>executed as:<BR><FONT color=#0000ff>./nb.pl&nbsp; 
01/20/03 06:00 01/22/03 23:59</FONT></FONT></P>
<P><FONT size=2>Notice that the time you enter does not have the seconds, it is 
only HH:MM, the seconds are appended as :00 to the input.</FONT></P>
<P><FONT size=2>To use it in automatic mode just type ./nb.pl and you are 
prompted through all the required information.&nbsp;&nbsp; A couple notes 
though, the time is checked to make sure that the hours are valid and the 
minutes are valid and the date is checked to make sure a valid month is entered 
and a valid number of days for that month.&nbsp; For example, you cannot say 
02/30/03 it will give an informational error and prompt for&nbsp; the same info 
until the user gets it right or &lt;CTR&gt;C is pressed.</FONT></P>
<P><FONT size=2>What it does not check is the dates against each other.&nbsp; 
It 
does not make sure that the '-d' date or tim&nbsp;is earlier than the '-e' date 
or time.&nbsp; Also, the year is only checked to make sure it is two 
digits.&nbsp; The value of the year you enter is not checked at all.&nbsp; Also 
the year is hardcoded with a '20' prefix.&nbsp; If you need this changed let me 
know.</FONT></P></BODY></HTML>

------_=_NextPart_001_01C2C485.4F4A4460--

------_=_NextPart_000_01C2C485.4F4A4460
Content-Type: application/octet-stream;
        name="nb.pl"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
        filename="nb.pl"

#!/usr/bin/perl -w=0A=
=0A=
=0A=
use strict;=0A=
=0A=
=0A=
##################=0A=
# Global Vars=0A=
##################=0A=
my ($Sdate, $Stime, $Edate, $Etime);=0A=
my $argcount =3D $#ARGV + 1;=0A=
my $command =3D '/usr/openv/netbackup/bin/admincmd/bpimagelist -A =
-media ';=0A=
my $outfile =3D '/tmp/list-bpimagelist';=0A=
=0A=
##################=0A=
# Eval Command line=0A=
##################=0A=
if ( ($argcount > 5) or (($argcount > 0) and ($argcount < 4)))=0A=
{=0A=
    print "Only 4 arguments are accepted\n";=0A=
    print "<Start Date> <Start Time> <End Date> <End Time>\n";=0A=
}=0A=
elsif ($argcount =3D=3D 4)=0A=
{=0A=
    chomp $ARGV[0];=0A=
    chomp $ARGV[1];=0A=
    chomp $ARGV[2];=0A=
    chomp $ARGV[3];=0A=
=0A=
    $Sdate =3D $ARGV[0];=0A=
    $Stime =3D $ARGV[1];=0A=
    $Edate =3D $ARGV[2];=0A=
    $Etime =3D $ARGV[3];=0A=
=0A=
    exit if (! check_date($Sdate));=0A=
    exit if (! check_time($Stime));=0A=
    exit if (! check_date($Edate));=0A=
    exit if (! check_time($Etime));=0A=
    execute_command($Sdate, $Stime, $Edate, $Etime);=0A=
    exit;=0A=
}=0A=
=0A=
=0A=
##################=0A=
# Main=0A=
##################=0A=
prompt_user();=0A=
if (display_entered())=0A=
{=0A=
    execute_command($Sdate, $Stime, $Edate, $Etime);=0A=
}=0A=
else=0A=
{=0A=
       print "Exiting\n";=0A=
}=0A=
=0A=
##################=0A=
# Subs=0A=
##################=0A=
=0A=
sub execute_command=0A=
{=0A=
    my $local_Sdate =3D shift;=0A=
    my $local_Stime =3D shift;=0A=
    my $local_Edate =3D shift;=0A=
    my $local_Etime =3D shift;=0A=
    my $local_command =3D $command.' -d '.$local_Sdate.' =
'.$local_Stime.':00 -e '.$local_Edate.' '.$local_Etime.':00'.' > =
'.$outfile;=0A=
=0A=
    print "Executing $local_command\n";=0A=
    system($local_command);=0A=
}=0A=
=0A=
sub prompt_user=0A=
{=0A=
    while (1)=0A=
    {=0A=
       print "Enter start date (mm/dd/yy): ";=0A=
        $Sdate =3D <>;=0A=
        chomp($Sdate);=0A=
        last if (check_date($Sdate));=0A=
    }=0A=
=0A=
    while (1)=0A=
    {=0A=
    print "Enter start time (hh:mm): ";=0A=
      $Stime =3D <>;=0A=
      chomp($Stime);=0A=
      last if (check_time($Stime));=0A=
    }=0A=
=0A=
    while (1)=0A=
    {=0A=
    print "Enter end date (mm/dd/yy): ";=0A=
      $Edate =3D <>;=0A=
      chomp($Edate);=0A=
      last if (check_date($Edate));=0A=
    }=0A=
=0A=
    while (1)=0A=
    {=0A=
    print "Enter end time (hh:mm): ";=0A=
      $Etime =3D <>;=0A=
      chomp($Etime);=0A=
      last if (check_time($Etime));=0A=
    }=0A=
=0A=
}=0A=
=0A=
=0A=
sub display_entered=0A=
{=0A=
    my $RETURN =3D 0;=0A=
    print "\n";=0A=
    print "You Entered:\n";=0A=
    print "Start Date:  $Sdate\n";=0A=
    print "Start Time:  $Stime\n";=0A=
    print "End Date:    $Edate\n";=0A=
    print "End Time:    $Etime\n";=0A=
    print "\nExecute with these dates/times [Yy/Nn]: ";=0A=
    my $ans =3D <>;=0A=
    chomp($ans);=0A=
=0A=
    $RETURN =3D 1 if (($ans eq ('Y'|'y')));=0A=
=0A=
    return $RETURN;=0A=
}=0A=
=0A=
=0A=
sub check_time=0A=
{=0A=
    my $RETURN =3D 1;=0A=
    my $time =3D shift;=0A=
    my ($hours, $minutes);=0A=
    #if (not($time =3D~ m/^(\d|\d\d)\:\d\d$/))=0A=
    if (not($time =3D~ m/^\d\d\:\d\d$/))=0A=
    {=0A=
        print "Time must be in HH:MM\n";=0A=
        $RETURN =3D 0;=0A=
        return $RETURN;=0A=
    }=0A=
=0A=
    ($hours, $minutes) =3D split(":",$time);=0A=
=0A=
    if ( ($hours > 23) or ($hours < 0) )=0A=
    {=0A=
        print "Hours must be between 00 and 23\n";=0A=
        $RETURN =3D 0;=0A=
    }=0A=
=0A=
    if ( ($minutes > 59) or ($minutes < 0) )=0A=
    {=0A=
        print "Minutes must be between 00 and 59\n";=0A=
        $RETURN =3D 0;=0A=
    }=0A=
=0A=
    return $RETURN;=0A=
}=0A=
=0A=
=0A=
sub check_date=0A=
{=0A=
    my %calendar =3D (=0A=
         1        =3D> 31,=0A=
         2        =3D> 28,=0A=
         3        =3D> 31,=0A=
         4        =3D> 30,=0A=
         5        =3D> 31,=0A=
         6        =3D> 30,=0A=
         7        =3D> 31,=0A=
         8        =3D> 31,=0A=
         9        =3D> 30,=0A=
         10       =3D> 31,=0A=
         11       =3D> 30,=0A=
         12       =3D> 31,);=0A=
=0A=
    my $RETURN =3D 1;=0A=
    my $date =3D shift;=0A=
    my ($day, $month, $year);=0A=
    =0A=
    #if (not ($date =3D~ m/^(\d|\d\d)\/(\d|\d\d)\/\d\d$/))=0A=
    if (not ($date =3D~ m/^\d\d\/\d\d\/\d\d$/))=0A=
    {=0A=
        print "Date must be in MM/DD/YY\n";=0A=
        $RETURN =3D 0;=0A=
        return $RETURN;=0A=
    }=0A=
    =0A=
    ($month, $day, $year) =3D split("/",$date);=0A=
    my $YYYY =3D '20'.$year;=0A=
    if (! $YYYY % 4) {$calendar{2} =3D '29'}; #leap year=0A=
=0A=
    $month =3D~ s/^0//;=0A=
    $day   =3D~ s/^0//;=0A=
=0A=
    if (( $month > 12 ) or ($month < 1))=0A=
    {=0A=
        print "Month must be between 01 and 12\n";=0A=
        $RETURN =3D 0;=0A=
        return $RETURN;=0A=
    }=0A=
=0A=
    if (( $day > $calendar{$month}) or ($day < 1))=0A=
    {=0A=
        print "Dates for month \'$month\' must be between ",=0A=
              "1 and $calendar{$month}\n";=0A=
        $RETURN =3D 0;=0A=
        return $RETURN;=0A=
    }=0A=
    return $RETURN;=0A=
}=0A=

------_=_NextPart_000_01C2C485.4F4A4460--