-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-batch-script.sh
executable file
·73 lines (61 loc) · 1.82 KB
/
run-batch-script.sh
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
#!/bin/bash
nnodes="1"
time_limit="120"
finish_filename="mirge-batch-finished"
batch_script_name="mirge-batch-script.sh"
queue_name="pdebug"
stdio_filename="mirge-batch-script-out.txt"
wait_duration="600"
working_directory="."
while getopts t:b:f:w:d: flag
do
case "${flag}" in
t) time_limit=${OPTARG};;
b) batch_script_name=${OPTARG};;
f) finish_filename=${OPTARG};;
w) wait_duration=${OPTARG};;
d) working_directory=${OPTARG};;
o) stdio_filename=${OPTARG};;
esac
done
echo "Time Limit: $time_limit";
echo "Batch script: $batch_script_name";
echo "Finish filename: ${finish_filename}";
echo "Working directory: ${working_directory}";
echo "Stdio filename: ${stdio_filename}";
BATCH_SCRIPT_NAME="${batch_script_name}"
BATCH_HOST=$(hostname)
rm -f ${finish_filename}
return_code=0
cd ${working_directory}
case $BATCH_HOST in
# --- Run the batch job through the queue on Lassen@LLC
lassen*)
echo "Resolved Host: Lassen"
BATCH_HOST="Lassen"
date
# ---- Submit the batch script and wait for the job to finish
bsub ${BATCH_SCRIPT_NAME}
sleep ${wait_duration}
iwait=0
while [ ! -f "${finish_filename}" ]; do
iwait=$((iwait+1))
if [ "$iwait" -gt ${time_limit} ]; then # give up after a while
printf "Timed out waiting on batch job.\n"
exit 1 # skip the rest of the script
fi
sleep 60
done
sleep 30 # give the batch system time to spew its junk into the log
fi
;;
# --- Run the "batch job" on unknown/generic machine
*)
printf "Host: Unknown\n"
. ${BATCH_SCRIPT_NAME} >& ${stdio_filename}
return_code=$?
;;
esac
date
cd -
return $return_code