-
Notifications
You must be signed in to change notification settings - Fork 2
/
jobSync
executable file
·89 lines (74 loc) · 2.23 KB
/
jobSync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Version 2.0
usage() {
echo "usage: jobSync QUEUE_TYPE JOB_NAME"
echo " QUEUE_TYPE = LUNA | JUNO | SGE"
exit
}
if [ "$#" -ne 2 ]; then
usage
fi
QUEUE=$1
JOBNAME=$2
if [ "$QUEUE" == "LUNA" ] || [ "$QUEUE" == "luna" ]; then
getLastJobNo() {
bjobs -UF 2>&1 | fgrep "Job Name" | egrep $JOBNAME \
| tail -1 | perl -ne '/Job <(\d+)[\[\]\d]*>/;print "$1\n"'
}
#LSFBIN=/common/lsf/9.1/linux2.6-glibc2.3-x86_64/bin
BACKOFF=2
HOLDJOB=$(getLastJobNo)
while [ "$HOLDJOB" != "" ]; do
echo
echo "Holding on" $HOLDJOB $(date) $(( BACKOFF - 1 ))
echo
bsub -We 1 -w "post_done($HOLDJOB)" -J bSync_$$ -K sleep $(( BACKOFF - 1 ))
BACKOFF=$(( BACKOFF / 2 + BACKOFF ))
if [ "$BACKOFF" -gt 1200 ]; then
BACKOFF=1200
fi
HOLDJOB=$(getLastJobNo)
done
elif [ "$QUEUE" == "JUNO" ] || [ "$QUEUE" == "juno" ]; then
getLastJobNo() {
bjobs -UF 2>&1 | fgrep "Job Name" | egrep $JOBNAME \
| tail -1 | perl -ne '/Job <(\d+)[\[\]\d]*>/;print "$1\n"'
}
#LSFBIN=/common/juno/OS7/10.1/linux3.10-glibc2.17-x86_64/bin
BACKOFF=2
HOLDJOB=$(getLastJobNo)
while [ "$HOLDJOB" != "" ]; do
echo
echo "Holding on" $HOLDJOB $(date) $(( BACKOFF - 1 ))
echo
bsub -W 1:00 -w "post_done($HOLDJOB)" -J bSync_$$ -K sleep $(( BACKOFF - 1 ))
BACKOFF=$(( BACKOFF / 2 + BACKOFF ))
if [ "$BACKOFF" -gt 1200 ]; then
BACKOFF=1200
fi
HOLDJOB=$(getLastJobNo)
done
elif [ "$QUEUE" == "SGE" ] || [ "$QUEUE" == "sge" ]; then
QRSH=/common/sge/bin/lx24-amd64/qrsh
USER=$(/usr/bin/whoami)
export TMPDIR=/ifs/data/${USER}/tmp
mkdir -p $TMPDIR
SEMAPHORE=$(mktemp -t QSYNC_XXXXXXXX)
echo SYNC $JOBNAME >$SEMAPHORE
date >>$SEMAPHORE
TAG=qSync.${JOBNAME} ##${SEMAPHORE##*/}
echo $TAG
sleep 2
while [ -e $SEMAPHORE ]; do
cat $SEMAPHORE
sleep 1
echo "Holding for" $JOBNAME, $SEMAPHORE
$QRSH -now no -hold_jid $JOBNAME -N $TAG /bin/rm $SEMAPHORE
#echo "===="
#cat $SEMAPHORE
#echo "--"
done
else
echo "Unknown QUEUE_TYPE = ["$QUEUE"]"
usage
fi