#!/usr/local/bin/perl

open (Record,">> /Net/acrobat/barrie/Gopher-Test/.record");
open (dot_file,"/Net/acrobat/barrie/Gopher-Test/.kill-tree");

$database_dir="/Net/acrobat/barrie/Gopher-Test/Data/";

$date = `date`;
print Record $date;

while (<dot_file>)
{
    if ($_ !~ /^$/)
    {
        ($oldsite, $oldsize) = split(/ /,$_);
    }
}

close (dot_file);

@ps_result = `ps aux | grep barrie | grep perl | grep tree`;

foreach (@ps_result)
{
    ($user, $pid, $pcpu, $pmem, $vsize, $rsize, $tt, $stat, $time, $command) =
     split(/\s+/,$_,10);
}

chop ($command);

($perl, $tree, $newsite) = split(/\s+/,$command);

$lscmd = "ls -l $database_dir$newsite*";
@ls_result = `$lscmd`;

foreach (@ls_result)
{
    ($a, $b, $c, $newsize, $e, $f, $g, $h) = split(/\s+/,$_);
}

if (($oldsite eq $newsite) && ($oldsize eq $newsize))
{
    print Record join (" ", $oldsite, $oldsize, $time),"\n";
    system ("kill -9 $pid"); 
}

open(dot_file,"> /Net/acrobat/barrie/Gopher-Test/.kill-tree");

print dot_file "$newsite $newsize";

exit(0);
