1 |
#! /usr/bin/env bash |
2 |
|
3 |
# $Header: /u/gcmpack/MITgcm_contrib/test_scripts/engaging/test_submit_engag,v 1.7 2018/08/16 13:31:15 jmc Exp $ |
4 |
# $Name: $ |
5 |
|
6 |
today=`date +%Y%m%d` |
7 |
dInWeek=`date +%a` |
8 |
|
9 |
if test $# = 0 |
10 |
then |
11 |
TEST_LIST='o64Adm gfoAdm gfoTlm ifcMp2 ifcMpi' |
12 |
#if test "x$dInWeek" = xSun ; then TEST_LIST="$TEST_LIST iad ifc oad" ; fi |
13 |
else |
14 |
TEST_LIST=$* |
15 |
fi |
16 |
|
17 |
QSUB="/usr/bin/sbatch" |
18 |
#QSTAT="/usr/bin/qstat -u $USER" |
19 |
QLIST="/usr/bin/squeue -u $USER" |
20 |
dNam='engaging' |
21 |
HERE="$HOME/test_$dNam" |
22 |
TST_DIR="/pool001/jm_c/test_$dNam" |
23 |
logPfix='test_submit' |
24 |
|
25 |
SUB_DIR="$HERE/engaging" |
26 |
OUT_DIR="$HERE/output" |
27 |
LOG_FIL="$OUT_DIR/$logPfix."`date +%m%d`".log" |
28 |
#SUB_DIR="$HERE/temp" |
29 |
|
30 |
#-- clean up old log files and start a new one: |
31 |
cd $OUT_DIR |
32 |
|
33 |
rm -f $logPfix.*.log_bak |
34 |
if test -f $LOG_FIL ; then mv -f $LOG_FIL ${LOG_FIL}_bak ; fi |
35 |
echo -n '-- Starting: ' | tee -a $LOG_FIL |
36 |
date | tee -a $LOG_FIL |
37 |
|
38 |
n=$(( `ls $logPfix.*.log | wc -l` - 10 )) |
39 |
if test $n -gt 0 ; then |
40 |
echo ' remove old log files:' | tee -a $LOG_FIL |
41 |
ls -lt $logPfix.*.log | tail -"$n" | tee -a $LOG_FIL |
42 |
ls -t $logPfix.*.log | tail -"$n" | xargs rm -f |
43 |
fi |
44 |
|
45 |
if test -f /etc/profile.d/modules.sh ; then |
46 |
. /etc/profile.d/modules.sh |
47 |
fi |
48 |
module list >> $LOG_FIL 2>&1 |
49 |
|
50 |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
51 |
#-- now really do something: |
52 |
|
53 |
JOB_LIST=$TEST_LIST |
54 |
NB_SUB_JOBS=0 |
55 |
for i in $JOB_LIST |
56 |
do |
57 |
sfx=`echo ${i} | sed -e 's/^.../&_/' -e 's/^o64/op64/' | tr '[:upper:]' '[:lower:]'` |
58 |
BATCH_SCRIPT="test_engag_$sfx" |
59 |
if test -f $SUB_DIR/$BATCH_SCRIPT ; then |
60 |
#- job name ( $JOB ) & output-file name ( $JOB.std??? ) must match |
61 |
# definition within $BATCH_SCRIPT slurm script |
62 |
JOB="${i}_tst" |
63 |
sJob=`printf "%8.8s" $JOB` #- squeue truncate name to only 1rst 8c |
64 |
#job_exist=`$QSTAT | grep $JOB | wc -l` |
65 |
job_exist=`$QLIST | grep $sJob | wc -l` |
66 |
if test "x_$job_exist" = x_0 ; then |
67 |
#-- move previous output file |
68 |
outList=`ls $JOB.std??? 2> /dev/null` |
69 |
if test "x$outList" != x ; then |
70 |
echo -n " moving job $JOB old output files:" | tee -a $LOG_FIL |
71 |
if test -d $OUT_DIR/prev ; then |
72 |
for xx in $outList ; do |
73 |
pp=$OUT_DIR/prev/$xx ; echo -n " $xx" | tee -a $LOG_FIL |
74 |
test -f $pp.sav && mv -f $pp.sav $pp.old |
75 |
test -f $pp && mv -f $pp $pp.sav |
76 |
chmod a+r $xx ; mv -f $xx $OUT_DIR/prev |
77 |
done |
78 |
echo " to dir ./prev" | tee -a $LOG_FIL |
79 |
else |
80 |
echo " <-- missing dir $OUT_DIR/prev" | tee -a $LOG_FIL |
81 |
fi |
82 |
else echo " no old output files from job '$JOB'" | tee -a $LOG_FIL |
83 |
fi |
84 |
#-- submit job |
85 |
echo -n "--> $JOB : " | tee -a $LOG_FIL |
86 |
$QSUB $SUB_DIR/$BATCH_SCRIPT | tee -a $LOG_FIL |
87 |
NB_SUB_JOBS=`expr $NB_SUB_JOBS + 1` |
88 |
else |
89 |
echo "--> $JOB :" | tee -a $LOG_FIL |
90 |
#$QSTAT | grep $JOB | tee -a $LOG_FIL |
91 |
$QLIST | grep $sJob | tee -a $LOG_FIL |
92 |
echo ' job already exist => skip this test' | tee -a $LOG_FIL |
93 |
fi |
94 |
else |
95 |
echo 'no file:' $BATCH_SCRIPT 'to submit' | tee -a $LOG_FIL |
96 |
fi |
97 |
done |
98 |
echo "info-sub-list: NB_SUB_JOBS='$NB_SUB_JOBS'" >> $LOG_FIL |
99 |
echo -n '-- Finished at: ' | tee -a $LOG_FIL |
100 |
date | tee -a $LOG_FIL |
101 |
|
102 |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
103 |
exit 0 |