Subversion Repositories sysadmin_scripts

Rev

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

Rev 21 Rev 22
Line 55... Line 55...
55
use Cwd qw();
55
use Cwd qw();
56
use File::Copy qw(move);
56
use File::Copy qw(move);
57
use File::Basename;
57
use File::Basename;
58
use File::stat;
58
use File::stat;
59
 
59
 
-
 
60
# http://computer-programming-forum.com/53-perl/843e6090fe295ffc.htm
-
 
61
# how to verify this script is not already running
-
 
62
# creates a lock file which only lasts the length of the script
-
 
63
# if we die before removing it, the lock is released.
-
 
64
use Fcntl qw(:flock);  #  imports some constants
-
 
65
my $LOCKFILE = '/tmp/archiveDirectories.lock';
-
 
66
open LOCK, ">>$LOCKFILE" or die ("Can't open lockfile $LOCKFILE: $!");
-
 
67
flock(LOCK, LOCK_EX) or die ("I'm already running"); 
-
 
68
 
60
our $VERSION = '1.0';
69
our $VERSION = '1.0';
61
 
70
 
62
my $DEBUG = 3;
71
my $DEBUG = 0;
63
 
72
 
64
my %config;
73
my %config;
65
 
74
 
66
my @DirectoriesToMove;
75
my @DirectoriesToMove;
67
 
76
 
Line 215... Line 224...
215
   my $projectName = shift;
224
   my $projectName = shift;
216
   my $suffix = shift;
225
   my $suffix = shift;
217
   my $logfile = $config{'local root dir'} . "/$projectName.$suffix";
226
   my $logfile = $config{'local root dir'} . "/$projectName.$suffix";
218
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
227
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
219
   my $now = sprintf( "%04d-%02d-%02d %02d:%-2d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec );
228
   my $now = sprintf( "%04d-%02d-%02d %02d:%-2d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec );
-
 
229
   # create the logfile if it doesn't exist and set it to rw by everyone
-
 
230
   unless ( -e $logfile ) {
-
 
231
      qx(touch '$logfile');
-
 
232
      qx(chmod 666 '$logfile');
-
 
233
   }
220
   open LOG, ">>$logfile" or die "could not write to $logfile: $!\n";
234
   open LOG, ">>$logfile" or die "could not write to $logfile: $!\n";
221
   while ( my $message = shift ) {
235
   while ( my $message = shift ) {
222
      print LOG "$now\t$message\n";
236
      print LOG "$now\t$message\n";
223
   }
237
   }
224
   close LOG;
238
   close LOG;