This is a very quick review. I would do more detail but when a script starts
with no warning and no stricture, there can be too much detail :) I'd suggest
starting with the warning and strict, then reposting.

On Fri, May 18, 2001 at 02:15:05PM -0400, Yacketta,Ronald J 
([EMAIL PROTECTED]) spew-ed forth:
> 
> #!/usr/local/bin/perl

#!/usr/local/bin/perl -w

use strict;

> 

[comments snipped]

When you turn on strict, all the variable initializations will need to be my'd.

> $g_version    =       "alpha 1.0";
> %months               =       (       "Jan"   =>      "01",
>                               "Feb"   =>      "02",
>                               "Mar"   =>      "03",
>                               "Apr"   =>      "04",
>                               "May"   =>      "05",
>                               "Jun"   =>      "06",
>                               "Jul"   =>      "07",
>                               "Aug"   =>      "08",
>                               "Sep"   =>      "09",
>                               "Oct"   =>      "10",
>                               "Nov"   =>      "11",
>                               "Dec"   =>      "12"
>                       );
> 
> %days         =       (       "1"     =>      "01",
>                               "2"     =>      "02",
>                               "3"     =>      "03",
>                               "4"     =>      "04",
>                               "5"     =>      "05",
>                               "6"     =>      "06",
>                               "7"     =>      "07",
>                               "8"     =>      "08",
>                               "9"     =>      "09"
>                       );
> 
> $TIME         =       scalar localtime(time-86400);
> $TIME         =~
> s/(\w\w\w)\s(\w\w\w)\s*(\d+)\s*(\d\d):(\d\d):(\d\d)\s*(\d\d)(\d\d)//;
> # I am almost positive this could be done cleaner, I wanted to use unless() 
> # but it never seemed to work, then again it could be my syntax
> if ( length($3) < 2 )
> {
>       $DAY            =       $days{$3};
> }
> else
> {
>       $DAY            =       $3;
> }
> 
> # I am not sure why I am doing these var's like this, maybes its my shell
> script
> # mentality and lack of know how with perl
> $MON          =       $months{$2};
> $YER          =       $8;
> $DATE         =       "$MON\/$DAY\/$YER";
> $TODAY                =       `/bin/date +%m/%d/%y`;
> #$NDATE               =       `/bin/date +%m_%d_%y`;
> $NDATE                =       $TODAY;
> $NDATE                =~      s/\//_/g;
> chomp ($NDATE);
> chomp ($TODAY);
> ######
> ######

I like the POSIX module for dates. Take a look at POSIX::strftime().

> 
> $MAIL         =       "/bin/mailx";
> $MMINFO               =       "/usr/sbin/mminfo";
> $NSRCLONE     =       "/usr/sbin/nsrclone";
> $GREP         =       "/usr/bin/grep";
> $DIR          =       "/var/tmp/clone_sets";
> $BACKINT      =       "$DIR/backint_clone";
> $CONFIG               =       "$DIR/wkiclone.cfg";
> $AWK          =       "/bin/awk";
> $CAT          =       "/bin/cat";
> $LP           =       "/usr/ucb/lpr/lpr -Phqit";
> $SORT         =       "/bin/sort";
> $WC           =       "/bin/wc -l";
> $WORKFILE     =       "$DIR/workfile";
> $VOLS         =       "$DIR/volfile";
> $VOLFILE      =       "$DIR/volumes";
> $BACKINT      =       "$DIR/backint_clone";
> $ONLINE               =       "$DIR/online_clone";
> $ARCHIVE      =       "$DIR/archive_clone";
> $EXCHANGE     =       "$DIR/exchange_clone";
> $FULL         =       "$DIR/full_clone";
> $CLONE_FILE   =       "$DIR/clone_file2";
> $REPORT               =       "$DIR/$NDATE"."_clone.rpt";
> 
> ##
> ##
> ############################################################################
> ####
> ## No need to edit below this line
> ##
> 
> 
> use Getopt::Long;
> use Time::Local;
> 
> $|=1;
> ##
> ## MAIN
> ##
> 
> # Options
> 
> # what an ugly hack this is!
> if ( -e $REPORT )
> {
> unlink $REPORT;
> unlink $CLONE_FILE;
> }
> 
> $usage = <<EOT
> Usage: wkiclone.pl [OPTION]...
> 
>   -a, --archive                   Clone Oracle online archives
>   -b, --backint                   Clone HQP brbackup and brarchive
>   -c, --complete                  Performs a complete clone of ALL backup 
>                                 types listed in this output
>                                 (same as wkiclone.pl -b -o -a -e -f)
>   -d, --debug                     enable debugging output, no actual cloning
> is performed
>   -e, --exchange                  Clone Exchange online backups
>   -f, --full                            Clone Group controlled FULL backups
>   -h, --help                      display this help and exit
>   -n, --nodebug                   disables debug; reduces debug level
>   -o, --online                    Clone Oracle online backups
>   -v, --version                   output version information and exit
> 
> Long options can be abbreviated, where such abbreviation is not ambiguous.
> 
> EOT
> ;
> 
> # Read Command Line Arguments
> 
> GetOptions(
>       "help|h"                        => \$opt_help,
>       "version|v"                     => \$opt_version,
>       "debug|d"                       => \$g_debug,
>       "nodebug|n"                     => \$g_nodebug,
>       "backint|b"                     => \$g_backint,
>       "online|o"                      => \$g_online,
>       "archive|a"                     => \$g_archive,
>       "exchange|e"                    => \$g_exchange,
>       "full|f"                        => \$g_full,
>       "complete|c"                    => \$g_comp,
> ) or die($usage);
> 
> if ($opt_help)
> {
>       print $usage;
>       exit(0);
> }
> 
> if ($opt_version)
> {
>       print "wkiclone.pl (WKIClone) $g_version\n"
>               . "Process to clone WKI critical savesets\n\n"
>               . "Copyright (C) 2001  Ronald J. Yacketta\n"
>               . "This is free software; see the source for copying
> conditions.  There is NO\n"
>               . "warranty; not even for MERCHANTABILITY or FITNESS FOR A
> PARTICULAR PURPOSE.\n";
>       exit(0);
> }
> 
> if (!$g_backint && !$g_online && !$g_archive && !$g_exchange & !$g_full )

Missing a & after $g_exchange

> {
>       $g_comp=1;
> }
> 
> # Thanxs to the folks at [EMAIL PROTECTED] for a boat load help here!
> # man that list is just a excellent resource of knowledge!
> my %servers = ();
> open(CFG,"$CONFIG") || die "could not open $CONFIG: $!";
> while ($line = <CFG>)
> {
>       chomp($line);
>       if ( $line =~ /^#/ ) { next; }
>         my ($name, $list) =   split /:/, $line;
>       $servers{$name}   =  [split ' ', $list ];
> 
> }
> close(BINT);

Where did the BINT filehandle come from?

> 
> $g_debug -= $g_nodebug;
> $g_debug = 0 if ($g_debug < 0);
> 
> # Lets ensure we have a clean REPORT file.
> if ( -e $REPORRT ) { unlink $REPORT; }

$REPORT, not $REPORRT. Didn't you already do this though?

> 
> # Open clean report file for appending
> open(RPT, ">>$REPORT") or die "Can't open $REPORT: $!";

If this may be run multiple times at the same time, you should do some file
locking on your $REPORT file.

> 
> # Lets begin the clone process with some generic log/informative verbage
> print "Starting WKI clone process for $DATE on ".localtime(time)."\n";
> 
> # drop a copy of the bootstrap into the report file
> # for future regeneration of our legato server
> #system "$MMINFO -B > $WORKFILE";
> 
> system "echo \"Starting WKI clone process for $DATE on `date`\" >> $REPORT
> ";

Whoa...

my $date = scalar localtime(time); # You may want to do this earlier and get
                                   # rid of your other call to localtime(time)
print RPT "Starting WKI clone process for $DATE on $date";


> #system "echo \"Legato Bootstrap information:\n\" >> $REPORT ; $CAT
> $WORKFILE >> $REPORT";

Please read perlopentut

> 
> if ( $g_backint || $g_comp )
> {
> 
> # My attempt to parse each value from each type of clone
> # to generate a clone report and saveset id's to clone
>       for $server (%servers) {
>                # It works! but man it is just plain uggggggggly!

for my $server (keys %servers) {

>                $start = @{$servers{$server}}[0];
>                $stop  = @{$servers{$server}}[1];
>               foreach $name (@{ $servers{$server} }) {
>                       if ($start eq $name || $stop eq $name ) { next; }
>                       @output = `$MMINFO -a -r
> \"savetime,volume,ssid,name\" -q \"location=sun_etl,savetime > $start 1 days
> ago,savetime < $stop today\" -c $name -V -o tR | sort -n -k 4,4 `;
>                       print $server."->".$name.": Cloning " . scalar
> @output . " savesets\n";
>                       shift(@output);
>                       print RPT "Clone report for $name from $start $DATE
> to $stop $TODAY \n";
>                       foreach $save (@output)         

foreach my $save (@output) 

>                       {
>                               # what a time save unpack is! man it is 100x
> better than
>                               # trying to regex the data out!
>                               ( $date,$volume,$ssid,$file) = unpack ("A9
> A15 A11 A*", $save);
>                               $date =~ s/ //g;
>                               $volume =~ s/ //g;
>                               $ssid =~ s/ //g;
>                               $file =~ s/ //g;
>                               print RPT "$date $ssid $file\n";
>                       }
>               }
>       }
>  
> }
> 

-- 
[Writing CGI Applications with Perl - http://perlcgi-book.com]
Number one ain't you... You ain't even number two.
        -- Frank Zappa

Reply via email to