#! /bin/sh # exit on error set -e # --- init ----------------------------------------------- # set program name and location: case $0 in /* ) script=$0 ;; * ) script="`/bin/pwd`/$0" ;; esac bindir=`/usr/bin/dirname ${script}` prog=`/bin/basename ${script}` # --- help --- DisplayHelp () { ${PAGER:-less} << EOF NAME $prog - store output USAGE #$prog $prog Post process output files. The script is called with this arguments from the 'run-tm5.jb' script. Arguments have the following meaning: : settings : main directory for output ('outputdir' in rcfile), e.g. \$TEMP/run.TM5-OUTPUT # : subdirectory created by 'run-tm5.jb' within # with a name including start and end time, e.g. # TM5_2002110100_2002110300 : directory with sources and scripts for this run, e.g. \$TEMP/run.TM5/xlf90-fast-R64 $prog -h,--help Display this help text. RCFILE The following settings are read from the rcfile : ! current implementation creates a tar file of directory ! and stores this in one or more destination directories (gss descriptions) output.store.destdirs : \${TEMP}/archive/ ecfs:/klm/archive ! gzip files before storage (T|F) ? output.store.compress : F ! remove files after store (T|F) ? output.store.clean : F EOF exit 0 } # err 'help text' err () { echo "$1" 1>&2 } # errit errit () { err "$prog - ERROR - Use '$prog --help' for more info." exit $1 } # --- arguments ------------------------ # set empty values rcfile='' outputdir='' #runname='' compdir='' # extract settings for arg in "$@" ; do case ${arg} in --help | -h ) DisplayHelp ;; * ) if [ -z "${rcfile}" ]; then rcfile=${arg} elif [ -z "${outputdir}" ]; then outputdir=${arg} #elif [ -z "${runname}" ]; then # runname=${arg} elif [ -z "${compdir}" ]; then compdir=${arg} else err "$prog - ERROR - unknown argument '${arg}'" errit 1 fi esac done if [ -z "${compdir}" ]; then err "$prog - ERROR - missing arguments ..." errit 1 fi # --- settings ----------------------------------------------------------- # read list with destinations: destdirs=`${bindir}/go_readrc ${rcfile} 'output.store.destdirs'` # compress ? compress=`${bindir}/go_readrc ${rcfile} 'output.store.compress' 'F'` # clean ? clean=`${bindir}/go_readrc ${rcfile} 'output.store.clean' 'F'` # extern: tar='/usr/bin/tar' gzip='/usr/bin/gzip' # --- begin ----------------------------------------------------------- echo "$prog - store output ..." # name of output directory includes time range: #outdir="${outputdir}/${runname}" outdir="${outputdir}" # tar file to contain sources: src_tar="${outdir}/src.tar" # tar sources: echo "$prog - tar sources ..." /bin/rm -f ${src_tar} ${src_tar}.gz ( cd ${compdir}/src ; ${tar} cf ${src_tar} *.[Ff]* *.h Makefile* ) ${gzip} -f ${src_tar} # goto main output directory: cd ${outputdir} ## tar output files: #tarfile="${runname}.tar" #echo "$prog - tar run output :" #${tar} cvf ${tarfile} ${runname} # compress ? if [ "${compress}" = "T" ]; then echo "$prog - compress ..." # loop over output files: for outfile in `/bin/ls` ; do case ${outfile} in *.gz ) ;; * ) ${gzip} -f ${outfile} ;; esac done fi # loop over all destinations: for destdir in ${destdirs} ; do echo "$prog - store in ${destdir} ..." #${bindir}/gss copy --mkdir ${tarfile} ${destdir}/${tarfile} # loop over output files: for outfile in `/bin/ls` ; do # skip some files ... skip='' case ${destdir}/${outfile} in ecfs:*/regions_*.hdf.gz ) skip='true' ;; ecfs:*/budget_*_glb3x2.hdf.gz ) skip='true' ;; esac if [ "${skip}" ]; then echo "$prog - ${outfile} (skip)" continue fi echo "$prog - ${outfile} ..." ${bindir}/gss copy --mkdir --force ${outfile} ${destdir}/${outfile} done done # clean if [ "${clean}" == "T" ]; then echo "$prog - clean ..." /bin/rm -f * #/bin/rm -f ${tarfile} fi # --- end -------------------------------------------------------------- echo "$prog - end"