2 ################################################################################
6 # Description: [Un]locks all vobs in the current region, reports results
7 # Author: Andrew@DeFaria.com
8 # Created: Mon Mar 15 08:48:24 PST 2004
9 # Modified: 2007/05/17 07:45:48
12 # (c) Copyright 2004, Andrew@DeFaria.com, all rights reserved.
14 ################################################################################
21 # This will be set in the BEGIN block but by putting them here the become
22 # available for the whole script.
35 # Extract relative path and basename from script name.
36 $0 =~ /(.*)[\/\\](.*)/;
38 $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
39 $me = (!defined $2) ? $0 : $2;
41 # Check to see if we are running on Windows
42 $windows = ($^O =~ /MSWin/) ? "yes" : "no";
45 $bin_path = "$abs_path";
46 $triggers_path = "$abs_path/../triggers";
47 $lib_path = "$abs_path/../lib";
48 $log_path = "$abs_path/../log";
49 $etc_path = "$abs_path/../etc";
51 # Add the appropriate path to our modules to @INC array.
52 unshift (@INC, "$lib_path");
57 # Store logfile in CM_TOOLS/logs
58 my $logfile = "$log_path/lockvobs.log";
60 # Production vob server
61 my $vob_server = defined $ENV {VOBSERVER} ? $ENV {VOBSERVER} : undef;
63 # Gotta be from somebody!
64 my $from = defined $ENV {FROM} ? $ENV {FROM} : undef;
66 # This should be changed to an email alias
69 # Who gets notified when there are errors
74 my $smtphost = "appsmtp";
77 my $exceptions_file = "$etc_path/vob_exceptions";
87 print "Usage $me:\t[-u] [-n] [-smtphost <smtphost>] [-to <email addresses]\n";
88 print "\t\t[-errors-to <email addresses>]\n";
90 print "\t-u\t\tUnlock vobs (default lock vobs)\n";
91 print "\t-smtphost\tSpecifies what SMTP host to use for mail (default\n";
92 print "\t\t\tnotesmail01)\n";
93 print "\t-to\t\tComma separated list (no spaces) of email addresses to\n";
94 print "\t\t\tsend output to (default: bsomisetty\@ameriquest.net,\n";
95 print "\t\t\tsgopavarapu\@ameriquest.net)\n";
96 print "\t-errors-to\tComma separated list (no spaces) of email addresses\n";
97 print "\t\t\tto send (only errors) to (default:\n";
98 print "\t\t\tadefaria\@ameriquest.net)\n";
105 open LOGFILE, ">>$logfile"
106 or die "Unable to open logfile: $logfile - $!";
108 print LOGFILE $msg . "\n";
114 my $smtphost = shift;
119 my $subject = $unlock eq "yes" ? "Unlock VOBs" : "Lock VOBs";
121 # Connect to mail server
122 my $smtp = Net::SMTP->new ($smtphost);
124 die "Unable to open connection to mail host: $smtphost\n" if !defined $smtp;
131 foreach (@errors_to) {
145 $smtp->datasend ("From: $from\n");
147 # Add @to and @errors_to
148 $smtp->datasend ("To: " . join (",", @to) . "\n");
151 $smtp->datasend ("Subject: $subject\n\n");
154 open LOGFILE, $logfile
155 or die "Unable to open logfile $logfile - $!\n";
158 $smtp->datasend ($_);
174 notify $smtphost, $from, $errors, $unlock;
188 return 1 if $item eq $_;
195 while ($#ARGV >= 0) {
196 if ($ARGV [0] eq "-u") {
202 if ($ARGV [0] eq "-n") {
208 if ($ARGV [0] eq "-smtphost") {
210 $smtphost = $ARGV [0];
215 if ($ARGV [0] eq "-to") {
217 @to = split /,/,$ARGV [0];
222 if ($ARGV [0] eq "-errors-to") {
224 @errors_to = split /,/,$ARGV [0];
232 Usage "Vob server hasn't been defined" if !defined $vob_server;
233 Usage "From has not been specified" if !defined $from;
234 Usage "To has not been specified" if @to;
235 Usage "Errors to has not been specififed" if @errors_to;
237 open EXCEPTIONS, $exceptions_file
238 or error "Unable to open exceptions file ($exceptions_file)", 1;
240 my @exceptions = <EXCEPTIONS>;
242 # Remove logfile if present
243 unlink ($logfile) if (-e $logfile);
246 open (VOBS, "cleartool lsvob -short -host $vob_server|")
247 or Error "Can't list vobs: $!";
252 chop if /\r/; # any carriage return
254 next if $#exceptions ne 0 and IsAMember ($_, @exceptions);
256 $_ = "\\" . $_ if $windows ne "yes";
259 if ($unlock eq "yes") {
260 if ($execute eq "no") {
261 print "[noexecute] cleartool unlock vob:$_\n";
263 system ("cleartool unlock vob:$_ >> $logfile 2>&1");
266 if ($execute eq "no") {
267 print "[noexecute] cleartool lock vob:$_\n";
269 system ("cleartool lock vob:$_ >> $logfile 2>&1");
274 my $status = $? >> 8;
281 my $status = $execute eq "yes" ? notify $smtphost, $from, $errors, $unlock : 0;