#! /usr/bin/env bash # $Header: /home/ubuntu/mnt/e9_copy/mitgcm.org/scripts/clean_subdir,v 1.1 2009/09/22 20:26:23 jmc Exp $ # # The purpose of this script is to clean-up (relatively) old monthly # collection of testreport results: # will replace all experiment sub-dir (in each testreport output dir) # with just 1 tar file (it reduces disk-space and number of files/dir # by almost 2 order of magnitude). # Note: Needs hand editing ! #- to run from any author machine: storeResDir='/net/orwell/export/export-9/mitgcm-testing/results' #- to run from orwell (better since it is disk intensive): storeResDir='/export/export-9/mitgcm-testing/results' echo -n "change dir to: " cd $storeResDir pwd listM='2006_10' #listM=`ls -1 -d 2006_1[1-2] 2007_[0-1][0-9] 2008_[0-1][0-9]` listM=`ls -1 -d 2009_0[1-3]` echo "listM='$listM'" #exit for MD in $listM do flag=0 echo "===============================================================" echo " -- process dir $MD :" echo "===============================================================" cd $MD out=$? if test $out != 0 ; then echo " cd $MD : error= $out" continue fi tStart=`date` listD=`ls -1 -d tr_*` #echo $listD for dd in $listD do if test $flag = 1 ; then continue ; fi own=-1 if test -d $dd ; then #echo "> $dd is dir" own=`ls -l -d $dd | grep -c $USER` fi if test $own = 0 ; then echo " $USER does not own dir: $dd : ==> skipped" fi if [ $own -gt 0 ] ; then xx=$dd.tar if test -f $dd/$xx -o -f $dd/$xx.gz ; then echo ' tar file exist:' ls -l $dd/${xx}* else #flag=1 echo -n "tar -cf $xx $dd ..." tar -cf $xx $dd out=$? if test $out = 0 ; then touch -r $dd/summary.txt $xx cd $dd nb=0; echo -n " ; rm -r [all dir] ..." listRM=`ls -1` for yy in $listRM do if test -d $yy ; then rm -r $yy nb=`expr $nb + 1` fi done cd .. echo " (total: $nb) done" gzip -9 $xx mv $xx.gz $dd #ls -l $dd else echo " : error= $out" fi fi fi done eStart=`date` echo " -- cleaning started at: $tStart" echo " ended at: $eStart" echo "===============================================================" cd .. done #exit