develooper Front page | perl.beginners | Postings from May 2007

logic not working

Thread Next
From:
Tony Heal
Date:
May 20, 2007 09:21
Subject:
logic not working
Message ID:
01c101c79afa$e99b7790$800101df@shipwreck
OK I am probably missing something stupid, but I can not get this to work. The output should be 'Daily-{day of
week)-{MMM}-{DD}-{YYYY}' for Sunday thru Friday and 'Weekly-{1|2|3}-{day of week)-{MMM}-{DD}-{YYYY} for Saturday and
every fourth Saturday should start rotating months 'Month-{1|2|3}-{day of week)-{MMM}-{DD}-{YYYY}

 

Anyone got any ideas?

 

Oh, there is some code at the front that changes the system date from May 1 to 31

 

Thanks

 

 

Tony

 

 

#!/usr/bin/perl

use warnings;

use strict;

my $today = `date +%m%d%H%M`;

my $count = "501";

while ($count lt 532){ 

my $that = "0$count" . "2100";

system("date $that");

my $backupBaseDir = '/gfsbackup';

my $logFile = "$backupBaseDir\/gfs_backup.log";

my $scpCMD = 'scp -i /usr/backup/.ssh/haddock';

my $backupDir = gfsBackup();

my @ePaceServers = ("silverfish", "catfish", "bonefish");

if ( ! -d $backupBaseDir )

{

            mkdir $backupBaseDir;

}

sub gfsBackup

{

my ($sec,$min,$hour,$mday,$mon,$yearOffset,$wday,$yday,$isdst)=localtime(time);

my $year = $yearOffset + 1900;

my ($weeksec,$weekmin,$weekhour,$weekmday,$weekmon,$weekyearOffset,$weekwday,$weekyday,$weekisdst)=localtime(time -
(84600 * 8));

my $weekyear = $weekyearOffset + 1900;

my ($msec,$mmin,$mhour,$mmday,$mmon,$myearOffset,$mwday,$myday,$misdst)=localtime(time - (84600 * 29));

my $myear = $yearOffset + 1900;

my $week = int($yday/7);

my $sevendays = (time - (84600 * 7));

my @days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

my ($directory, @dir, $month, $gfsDir, $DatedgfsDir, $monthDirectory, @monthDir, $lastWeek, $dirtemp);

if ( $days[$wday] =~ "Saturday" )

            {

            opendir (DIR, $backupBaseDir);

            my @readdir = readdir(DIR);

            closedir(DIR);

            while (<@readdir>)

            {

                        $directory = $_;

                        print "directory = $directory\n";

                        if ( $directory =~ "$months[$weekmon]-$weekmday-$weekyear" )

                        {

                                    @dir = split( /-/, $directory);

                                    if ( $dir[0] =~ "Monthly" )

                                    {

                                                $gfsDir = "Weekly-1";

                                    }

                                    if ( $dir[0] =~ "Weekly" )

                                    {

                                                if ( $dir[1] lt 3 )

                                                            {

                                                                        my $weekcount = $dir[1] + 1;

                                                                        $gfsDir = "Weekly-$weekcount";

                                                            }

                                                if ( $dir[1] eq 3 )

                                                            {

                                                            my $monthcount = `ls $backupBaseDir | grep
"$months[$mmon]-$mmday-$myear" | cut -d- -f2`;

                                                            if ( $monthcount eq "13" )

                                                                        {

                                                                                    $gfsDir = "Monthly-1";

                                                                        }

                                                            else

                                                                        {

                                                                                    $monthcount++;

                                                                                    $gfsDir = "Monthly-$monthcount";

                                                                        }

                                                            }

                                    }

                                    last;

                        }

            }

            }

            elsif ( $days[$wday] =~ "Saturday" )

            {

                        $gfsDir = "Weekly-1";

                        last;

            }

if ( ! $gfsDir )

{

            $gfsDir = "Daily-$days[$wday]-$months[$mon]-$mday-$year";

            mkdir "$backupBaseDir/$gfsDir";

            chdir "$backupBaseDir/$gfsDir";

            return $gfsDir;

}

else

{

            $DatedgfsDir = "$gfsDir-$days[$wday]-$months[$mon]-$mday-$year";

            mkdir "$backupBaseDir/$DatedgfsDir";

            chdir "$backupBaseDir/$DatedgfsDir";

            $gfsDir = $DatedgfsDir;

            return $gfsDir;

}

}

$count++;}

 


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About