#! /usr/bin/env bash # $Header: /home/ubuntu/mnt/e9_copy/MITgcm_contrib/test_scripts/engaging/test_submit_engag,v 1.10 2021/04/20 04:31:39 jmc Exp $ # $Name: $ today=`date +%Y%m%d` dInWeek=`date +%a` #- select type of BATCH_SCRIPT to submit: typ='' if [ $# -ge 1 ] ; then case $1 in 'c6'|'c7') typ=".$1" ; shift ;; esac fi if test $# = 0 then TEST_LIST='o64Adm gfoAdm gfoTlm ifcMp2 ifcMpi' #if test "x$dInWeek" = xSun ; then TEST_LIST="$TEST_LIST iad ifc oad" ; fi else TEST_LIST=$* fi QSUB="/usr/bin/sbatch" #QLIST="/usr/bin/qstat -u $USER" QLIST="/usr/bin/squeue -u $USER" dNam='engaging' HERE="$HOME/test_$dNam" TST_DIR="/pool001/jm_c/test_$dNam" logPfix='test_submit' SUB_DIR="$HERE/engaging" OUT_DIR="$HERE/output" LOG_FIL="$OUT_DIR/$logPfix."`date +%m%d`".log" #SUB_DIR="$HERE/temp" #-- clean up old log files and start a new one: cd $OUT_DIR rm -f $logPfix.*.log_bak if test -f $LOG_FIL ; then mv -f $LOG_FIL ${LOG_FIL}_bak ; fi echo -n '-- Starting: ' | tee -a $LOG_FIL date | tee -a $LOG_FIL n=$(( `ls $logPfix.*.log | wc -l` - 10 )) if test $n -gt 0 ; then echo ' remove old log files:' | tee -a $LOG_FIL ls -lt $logPfix.*.log | tail -"$n" | tee -a $LOG_FIL ls -t $logPfix.*.log | tail -"$n" | xargs rm -f fi if test -f /etc/profile.d/modules.sh ; then . /etc/profile.d/modules.sh fi module list >> $LOG_FIL 2>&1 #---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| #-- now really do something: JOB_LIST=$TEST_LIST NB_SUB_JOBS=0 for i in $JOB_LIST do sfx=`echo ${i} | sed -e 's/^.../&_/' -e 's/^o64/op64/' | tr '[:upper:]' '[:lower:]'` BATCH_SCRIPT="test_engag_${sfx}${typ}" if test -f $SUB_DIR/$BATCH_SCRIPT ; then #- job name ( $JOB ) & output-file name ( $JOB.std??? ) must match # definition within $BATCH_SCRIPT slurm script JOB="${i}_tst" sJob=`printf "%8.8s" $JOB` #- squeue truncate name to only 1rst 8c #job_exist=`$QLIST | grep $JOB | wc -l` job_exist=`$QLIST | grep $sJob | wc -l` if test "x_$job_exist" = x_0 ; then #-- move previous output file outList=`ls $JOB.std??? 2> /dev/null` if test "x$outList" != x ; then echo -n " moving job "$JOB" old output files:"| tee -a $LOG_FIL if test -d $OUT_DIR/prev ; then for xx in $outList ; do pp=$OUT_DIR/prev/$xx ; echo -n " $xx" | tee -a $LOG_FIL test -f $pp.sav && mv -f $pp.sav $pp.old test -f $pp && mv -f $pp $pp.sav chmod a+r $xx ; mv -f $xx $OUT_DIR/prev done echo " to dir ./prev" | tee -a $LOG_FIL else echo " <-- missing dir $OUT_DIR/prev" | tee -a $LOG_FIL fi else echo " no old output files from job '$JOB'" | tee -a $LOG_FIL fi #-- submit job echo -n "--> $JOB : $BATCH_SCRIPT , " | tee -a $LOG_FIL $QSUB $SUB_DIR/$BATCH_SCRIPT | tee -a $LOG_FIL NB_SUB_JOBS=`expr $NB_SUB_JOBS + 1` else echo "--> $JOB :" | tee -a $LOG_FIL $QLIST | grep $sJob | tee -a $LOG_FIL echo ' job already exist => skip this test' | tee -a $LOG_FIL fi else echo 'no file:' $BATCH_SCRIPT 'to submit' | tee -a $LOG_FIL fi done #echo "info-sub-list: NB_SUB_JOBS='$NB_SUB_JOBS'" >> $LOG_FIL echo "Submitted $NB_SUB_JOBS jobs from dir: $SUB_DIR" | tee -a $LOG_FIL echo -n '-- Finished at: ' | tee -a $LOG_FIL date | tee -a $LOG_FIL #---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| exit 0