--- bin/deleteccf 2018/01/15 10:02:11 1.6 +++ bin/deleteccf 2021/07/27 13:09:16 1.8 @@ -1,49 +1,46 @@ -#! /xdata/ccflib/perl5/perlbrew/perls/perl-5.18.4/bin/perl -w +#! /usr/bin/env perl +#! /xdata/ccflib/perl5/perlbrew/perls/perl-5.18.4/bin/perl # -# $Id: deleteccf,v 1.5 2014/12/02 14:06:51 ccflib Exp $ +# $Id: deleteccf,v 1.7 2020/07/04 11:59:30 ccflib Exp $ # -# This script simply deletes all CCFs put in the subdir ccfdev/deleted. -# It is intended to be run by a crontab, either on xvsoc01 or in sasbld01 +# Script to be run from crontab to delete any CCFs in +# /home/ccflib/ftp-area/private/ccfdevel/deleted require 5; use strict; +use warnings; use vars '%ENV'; -use lib "$ENV{'HOME'}/cgi"; -$ENV{'PATH'} .= "$ENV{'HOME'}/bin:"; -# Can not use Ccflib.pm located in $HOME/cgi because it has definitions for directories only on xvsoc01. -# use Ccflib; +# If DEBUG is set, warns without executing -my $host=qx/\/bin\/hostname | cut -d. -f1/ ; -my $homedir="/home/ccflib" ; +my $debug = ""; +if ( $ENV{'DEBUG'} ) { + $debug = "$ENV{'DEBUG'}"; +} + + +my $host=qx/\/bin\/hostname/ ; chomp($host); -$homedir="/data/xmm/ccflib" if ( $host eq "xvsoc01" ) ; -chdir "$homedir/ftp-area/private/ccfdevel/deleted/" ; +chdir "/home/ccflib/ccf_ftp/private/ccfdevel/deleted/"; + my $deletes; foreach my $ccf (glob("*.CCF")){ - qx/rm -f $ccf/; - if(! $? >> 8){ - warn("Deletion of $ccf failed\n"); - } else { - $deletes .= "$ccf "; - } + if ($debug) { + print "$ccf is marked for deletion\n"; + } else { + print "Going to delete $ccf\n"; + unlink $ccf; + if(! $? >> 8){ + warn("Deletion of $ccf failed\n"); + } else { + $deletes .= "$ccf "; + } + } } -if($deletes){ - print "The following constituents were found in the removed subdirectory:\n"; - print "$deletes\n"; - print "Now they have been definetely erased.\n"; +if(! $debug && $deletes){ + print "Script deleteccf running on $host\n"; + print "Removed CCFs:\n"; + print " $deletes\n"; } - -##my $x = qx/ccfnotify -t development -d $deletes/; -## -##if(! $? >> 8){ -## warn("Notification failed\n"); -##} - - - - - -