Index: /trunk/tools/stsci_disks/p0_large.pl
===================================================================
--- /trunk/tools/stsci_disks/p0_large.pl	(revision 38646)
+++ /trunk/tools/stsci_disks/p0_large.pl	(revision 38646)
@@ -0,0 +1,150 @@
+#! /usr/bin/env perl
+
+use DBI;
+use PS::IPP::Config 1.01 qw( :standard );
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::List qw( parse_md_list );
+use IPC::Cmd 0.36 qw( can_run run );
+use Carp;
+use Pod::Usage qw( pod2usage );
+
+use Nebulous::Server::SQL;
+use Nebulous::Client;
+use SQL::Interp qw( sql_interp );
+use strict;
+use warnings FATAL => qw( all );
+use Getopt::Long qw( GetOptions :config auto_help auto_version );
+use File::Basename;
+
+my ($host,$volume,$dir);
+GetOptions(
+    'host=s' => \$host,
+    'volume=s' => \$volume,
+    'dir=s'   => \$dir) || pod2usage(2 );
+
+my (    $db, $dbhost, $dbpass, $dbuser);
+my $conffile = "/home/panstarrs/ipp/ippconfig/nebulous.config";
+if (-e $conffile) {
+#    printf STDERR "found config\n";
+    open(IN,$conffile);
+    while(<IN>) {
+        chomp;
+        if ($_ =~ /NEB_DB\s+/) {
+            $db = (split /\s+/,$_)[2];
+        }
+        elsif ($_ =~ /NEB_DBHOST/) {
+            $dbhost = (split /\s+/,$_)[2];
+        }
+        elsif ($_ =~ /NEB_USER/) {
+            $dbuser = (split /\s+/,$_)[2];
+        }
+        elsif ($_ =~ /NEB_PASS/) {
+            $dbpass = (split /\s+/,$_)[2];
+        }
+    }
+    close(IN);
+#    print STDERR  "$db $dbhost $dbuser $dbpass\n";
+}
+
+pod2usage( -msg => "Cannot configure nebulous database", -exitval => 2) unless
+    defined $host && defined $volume && defined $dir && 
+    defined $db && defined $dbhost && defined $dbuser && defined $dbpass;
+
+my $host_check = `hostname`;
+chomp($host_check);
+if ($host ne $host_check) {
+    die "Required to run on $host.  not on $host_check\n";
+}
+
+my $dbh = DBI->connect(
+    "DBI:mysql:database=$db:host=$dbhost",
+    $dbuser,
+    $dbpass,
+    {
+        RaiseError => 1,
+        PrintError => 0,
+        AutoCommit => 0,
+    },
+    );
+my $sql = Nebulous::Server::SQL->new();
+
+my $server = $ENV{'NEB_SERVER'};
+my $neb = Nebulous::Client->new(
+    proxy => "$server",
+    );
+
+
+my $time = time();
+my $logDest = "neb://any/stsci_shuffle/large/${host}.${volume}/${dir}.log.${time}";
+my $ipprc = PS::IPP::Config->new( "GPC1" ) or die "Could not create config object.\n";
+$ipprc->redirect_output($logDest) or die "Could not redirect output to logfile ${logDest}\n";
+
+my @rsync_vols;
+if ($host =~ /stsci0/) {
+    push @rsync_vols, 'ipp096.0';
+}
+else {
+    if ($volume == 0) {
+	push @rsync_vols, 'ippb06.0';
+	push @rsync_vols, 'ipp074.0';
+    }
+    elsif ($volume == 1) {
+	push @rsync_vols, 'ippb06.1';
+	push @rsync_vols, 'ipp076.0';
+    }
+    elsif ($volume == 2) {
+	push @rsync_vols, 'ippb06.2';
+	push @rsync_vols, 'ipp079.0';
+    }
+}
+
+
+
+
+my $root = "/data/${host}.${volume}/nebulous/${dir}";
+my @subdirectories = <$root/*>;
+foreach my $subdir (@subdirectories) {
+    my @files = <${subdir}/*>;
+    foreach my $f (@files) {
+	if ($f =~ /LAP.PV3.20140730/) { next; }
+	
+	my @stat = stat($f);
+	my $limit = 10 * 1024 * 1024; # stat returns bytes, so 100 * meg * k 
+#	print "$f $stat[7]\n"; die;
+	if ($stat[7] > $limit) {
+	    my $ins_id = $f;
+	    $ins_id =~ s/^$subdir\///;
+	    $ins_id =~ s/\..*//;
+
+	    my $key = $f;
+	    $key =~  s/.*\/${ins_id}\.//;
+	    $key =~  s%:%/%g;
+		
+	    my $uris = $neb->find_instances($key);
+	    my $found = 0;
+	    foreach my $uri (@{ $uris }) {
+		if ($uri eq "file://${f}") {
+		    $found = 1;
+		}
+	    }
+	    if ($#{ $uris } == -1) { # true orphan
+		$found = -1;
+	    }
+	    print "$f $stat[7] $key $found\n";
+	    if ($found == 0) {
+#		print "rm $f\n";
+		unlink($f);
+		foreach my $rsync (@rsync_vols) {
+		    my $test_f = $f;
+		    $test_f =~ s%^/data/%%;
+		    $test_f = "/data/${rsync}/stsci_shuffle/${test_f}";
+		    if (-e $test_f) {
+			unlink($f);
+#			print "rm $test_f\n";
+		    }
+		}
+	    }
+	}
+    }
+#    print STDERR "$subdir\n";
+}
