Subversion Repositories sysadmin_scripts

Rev

Rev 28 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28 Rev 29
Line 204... Line 204...
204
sub validateTarget {
204
sub validateTarget {
205
   my ( $remoteServer, $remoteStaging, $remoteTarget, $directory, $checksum ) = @_;
205
   my ( $remoteServer, $remoteStaging, $remoteTarget, $directory, $checksum ) = @_;
206
   my $md5sum = `ssh $remoteServer "find '$remoteStaging/$directory' -type f -exec md5sum \\{\\} \\; | cut -d' ' -f1 | sort | md5sum | cut -d' ' -f1"`;
206
   my $md5sum = `ssh $remoteServer "find '$remoteStaging/$directory' -type f -exec md5sum \\{\\} \\; | cut -d' ' -f1 | sort | md5sum | cut -d' ' -f1"`;
207
   chomp $md5sum;
207
   chomp $md5sum;
208
   if ( $checksum eq $md5sum ) {
208
   if ( $checksum eq $md5sum ) {
209
      if ( defined ( $config{ 'final procedure' } ) ) {
-
 
210
         my $result = $config{ 'final procedure' }->( $remoteServer, $remoteStaging, $remoteTarget, $directory );
-
 
211
         &logit( $result ) if ( $result );
209
      &logit( "checksums match" );
212
      } # do the final procedure, if it exist
210
      return 1;
213
   } else {
211
   } else {
214
      &logit( "Invalid checksum moving directory $directory" );
212
      &logit( "Invalid checksum moving directory $directory" );
215
      return 0;
213
      return 0;
216
   }
214
   }
217
}
215
}
218
 
216
 
219
# simple little logger that records some information   
217
# simple little logger that records some information   
220
sub logit {
218
sub logit {
221
   my $projectName = shift;
219
   my $projectName = shift;
222
   my $suffix = shift;
220
   my $suffix = shift;
-
 
221
   $suffix = $config{'log suffix'} unless $suffix;
223
   my $logfile = $config{'local root dir'} . "/$projectName.$suffix";
222
   my $logfile = $config{'local root dir'} . "/$projectName.$suffix";
224
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
223
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
225
   my $now = sprintf( "%04d-%02d-%02d %02d:%-2d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec );
224
   my $now = sprintf( "%04d-%02d-%02d %02d:%-2d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec );
226
   # create the logfile if it doesn't exist and set it to rw by everyone
225
   # create the logfile if it doesn't exist and set it to rw by everyone
227
   unless ( -e $logfile ) {
226
   unless ( -e $logfile ) {
Line 328... Line 327...
328
      &logit( $directory, $config{'log suffix'},  "Error, move aborted" );
327
      &logit( $directory, $config{'log suffix'},  "Error, move aborted" );
329
      &logit( $directory, $config{'error suffix'},  $error );
328
      &logit( $directory, $config{'error suffix'},  $error );
330
   }
329
   }
331
}
330
}
332
 
331
 
-
 
332
 
333
# done with that, now we need to see if there is anything in the staging area
333
# done with that, now we need to see if there is anything in the staging area
334
# that needs to be sent to the remote server
334
# that needs to be sent to the remote server
335
`mkdir -p $config{'local staging area'}` unless -d $config{'local staging area'};
335
`mkdir -p $config{'local staging area'}` unless -d $config{'local staging area'};
336
opendir( my $dh, $config{'local staging area'} ) or die "Could not read $config{'local staging area'}: $!\n";
336
opendir( my $dh, $config{'local staging area'} ) or die "Could not read $config{'local staging area'}: $!\n";
337
my @directories;
337
my @directories;
Line 371... Line 371...
371
   } else {
371
   } else {
372
      &logit( $dirname, $config{'error suffix'}, "Unable to validate target for $dirname" );
372
      &logit( $dirname, $config{'error suffix'}, "Unable to validate target for $dirname" );
373
   }
373
   }
374
}
374
}
375
 
375
 
-
 
376
if ( defined ( $config{ 'final procedure' } ) ) {
-
 
377
   my $dirs = &runRemoteCommand( $config{'target server'},"ls -p $config{target server}/$config{target staging area} | grep /" );
-
 
378
   my @dirs = split( "\n", $dirs );
-
 
379
   foreach my $thisDir ( @dirs ) {
-
 
380
      my $result = $config{ 'final procedure' }->( $remoteServer, $remoteStaging, $remoteTarget, $directory );
-
 
381
      &logit( $result ) if ( $result );
-
 
382
   }
-
 
383
} # do the final procedure, if it exist
-
 
384
 
-
 
385
 
376
 
386
 
377
1;
387
1;