#!/usr/bin/perl # ************************************************************************** # # get_dates.prl written by Chris Evans (C.Evans@sghms.ac.uk) # # program puts the current time and date stamps of files into a file # # These can then be used by companion program touchback.prl to reset # # time and date stamps on files after minor tinkering # # # # The program takes as input in the variables declared immediately below # # $filemask -- file mask (appropriate to the OS) for the find command # # $outputdir -- the directory into which to put these files # # $menu -- filename for the menu to all other reports # # $report -- filename for the directory order output # # $time_rep -- filename for the modification time sorted output # # $other_rep -- filename for the files other than *.htm? # # $startdir -- directory from which to start the recursive search # # $www_offset -- any additional directory reference that accounts for # # a possible difference between the root used by unix for the # # search versus that shown to the world by the HTTP server in use # # This last variable may seem odd but on our local machine the root # # shown to the outside world by the server is at: # # /usr1/www/pages/ # # but my pages (from which I want the search for *.htm files to # # start is at: # # /usr1/www/pages/mhs/psychotherapy/ # # giving the value for $www_offset of /usr1/www/pages # # # # file written by Chris Evans (C.Evans@sghms.ac.uk) 22.ii.96 # # copyright Chris Evans _BUT_ feel free to distribute this subject to the # # following requirements: # # 1) you do not make a profit on the distribution # # 2) you retain this header information in full # # I would also very much appreciate feedback (I know the programming is # # awful, it's the first piece of PERL I've written and I'm a psychodynamic # # psychotherapist with no intention of giving up my day job so no flames if # # you can resist the temptation) and a copy of enhanced versions if you do # # hack this into something better # # # # Chris Evans (C.Evans@sghms.ac.uk) Section of Psychotherapy, # # St. George's Hospital Medical School, Cranmer Terrace, # # London, SW17 0RE, Britain # # ************************************************************************** # $outputdir = "/usr1/www/pages/mhs/psychotherapy/dir/"; $menu = "menu.htm"; $report = "htm_dir.htm"; $time_rep = "time_dir.dat"; $startdir = "/mhs/psychotherapy"; $www_offset = "/usr1/www/pages"; $filemask = "*.htm"; # sort out the location that the server will show for files $http_rep_dir = $outputdir; $http_rep_dir =~ s|$www_offset||o; # o switch as the value of $www_offset is fixed open (TIME, ">$outputdir$time_rep") || die "Couldn't open $outputdir$time_rep\n"; open(FIND, "find . -name \"$filemask\" -print |") || die "Couldn't run find: $!\n"; while ($filename = ) { undef $time; undef $size; chop $filename; # get data on the file ($nsize,$time) = (stat($filename))[7,9]; #use the 7th & 9th items in the stat array # reformat the data ($s, $m, $h, $day, $mon, $yr) = (localtime($time))[0,1,2,3,4,5]; $tot_size += $nsize; $size = &commas9($nsize); $h = &two_digits($h); $m = &two_digits($m); $s = &two_digits($s); $day = &two_digits($day); $ntime = $h.":".$m.":".$s; $montxt = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon]; $mon++; $mon = &two_digits($mon); # reformat the filename to the http server form $href = $filename; $href =~ s|.|$startdir|o; $touch = $mon.$day.$h.$m.$yr; $filedat{$filename} = join(';', $nsize, $size, $ntime, $day, $montxt, $yr, $time, $mon, $touch); print TIME "$filename;$filedat{$filename}\n"; } close TIME; # ****************************************************# # subroutines # # ****************************************************# sub two_digits { local ($_) = @_; if (length($_) == 0) { $_ = "00"; } elsif (length($_) == 1) { $_ = "0".$_; } elsif (length($_) > 2) { die "Supplied a number of more than 2 digits to two_digits\n"; } $_; } sub commas9 { local($_) = @_; 1 while s/(.*\d)(\d\d\d)/$1,$2/; while (length($_) < 9) { $_ = " ".$_; } $_; }