1#!/usr/local/bin/perl
2#
3#  Purpose:
4#  FlowViewer_CleanFiles is a utility for cleaning out temporary files
5#  that have been left over from debugging (e.g. $debug_files = 'Y')
6#  or are intermediate files generated during the tool invocations.
7#  All files older than $remove_files_time will be removed from the
8#  $working_directory. This can be run from crontab.
9#
10#  Description:
11#
12#  Input arguments (received from the form):
13#  Name                 Description
14#  -----------------------------------------------------------------------
15#  none
16#
17#  Modification history:
18#  Author       Date            Vers.   Description
19#  -----------------------------------------------------------------------
20#  J. Loiacono  04/01/2007      3.2     Original released version
21#  J. Loiacono  12/07/2007      3.3     Minor fixes
22#  J. Loiacono  02/14/2008      3.3.1   Minor re-alignment
23#  J. Loiacono  03/17/2011      3.4     Keep from deleting new save logo's
24#  J. Loiacono  05/08/2012      4.0     Removed removal from Reports Directory
25#  J. Loiacono  09/11/2013      4.2.1   Fixed for removing directories
26#
27#$Author$
28#$Date$
29#$Header$
30#
31###########################################################################
32#
33#               BEGIN EXECUTABLE STATEMENTS
34#
35
36use FlowViewer_Configuration;
37use FlowViewer_Utilities;
38use File::stat;
39
40$current_time = time;
41$start_time        = epoch_to_date($current_time);
42$work_files_time   = epoch_to_date($current_time - $remove_workfiles_time);
43$graph_files_time  = epoch_to_date($current_time - $remove_graphfiles_time);
44
45print "\nThis FlowViewer_CleanFiles run started: $start_time\n\n";
46
47# Clean out the Work directory according to 'remove_workfiles_time'
48
49print "Removing files from $work_directory older than: $work_files_time\n\n";
50
51while ($next_file = <$work_directory/*>) {
52
53	$last_access = stat($next_file)->mtime;
54        ($directory,$filename) = $next_file =~ m/(.*\/)(.*)$/;
55	$file_age = $current_time - $last_access;
56
57	if (substr($filename,0,16) eq "FlowGrapher_sort") { next; }
58
59	if ($file_age > $remove_workfiles_time) {
60		print "  deleting $next_file\n";
61		$remove_command = "rm -rf $next_file";
62		system($remove_command);
63	}
64}
65
66# Clean out the Graph directory according to 'remove_workfiles_time'
67
68print "\nRemoving files from $graphs_directory older than: $graph_files_time\n\n";
69
70while ($next_file = <$graphs_directory/*>) {
71
72	if ($next_file eq "$save_directory")    { print "  skipping $next_file\n"; next; }
73
74        ($directory,$filename) = $next_file =~ m/(.*\/)(.*)$/;
75
76	$last_access = stat($next_file)->mtime;
77        ($directory,$filename) = $next_file =~ m/(.*\/)(.*)$/;
78	$file_age = $current_time - $last_access;
79
80	if ($file_age > $remove_graphfiles_time) {
81		print "  deleting $next_file\n";
82		$remove_command = "rm -rf $next_file";
83		system($remove_command);
84	}
85}
86