1 #!/usr/bin/perl -w
2 # File: files_writable.pl
3 # Author: Tom Large - tlarge@thelug.org
4 # Location: http://www.thelug.org/docs/
5 # Description: Takes a list of files, and determines if they
6 # are writable. This is useful in situations where a file
7 # may still be streaming in. Some operating systems will
8 # report the file as complete and whole--file size and time
9 # stamp included--even while it is still in transit. This
10 # determines if a file has finished arriving by checking to
11 # see if it can me opened.
12
13 my $timer = (time);
14 my $log_dir = '/Logs/Cache';
15 my $ready = "no";
16
17 opendir THISDIR, $log_dir or die "Can't open directory: $!";
18 @DIR_FILES = readdir THISDIR;
19 closedir THISDIR;
20
21 foreach (@DIR_FILES)
22 {
23 next if m/^\.+$/;
24 push(@LOG_FILE, "$_");
25 }
26
27 foreach $LOG_FILE(@LOG_FILE)
28 {
29 $ready = "no";
30 print "Working: $LOG_FILE\n";
31 $current_file = "$log_dir/$LOG_FILE";
32 while ($ready eq "no")
33 {
34 sleep 1;
35 open(THE_FILE, "<$current_file") or (next);
36 close (THE_FILE);
37 print "$LOG_FILE is ready.\n";
38 $ready = "yes";
39 }
40 }
41
42 my $new_timer = (time - $timer);
43 print "\nTook $new_timer seconds.\n";
syntax highlighted by Code2HTML, v. 0.9.1