-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_launch_jupyter.sh
60 lines (55 loc) · 2.12 KB
/
auto_launch_jupyter.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
#!/bin/bash
# exit when a bash command fails
set -e
unset XDF_RUNTIME_DIR
RES=$(sbatch sbatch_jupyter.sh)
jobid=${RES##* }
tries=1
wait=1
echo "Checking job status.."
while :
do
status=$(scontrol show job $jobid | grep JobState | awk '{print $1}' | awk -F= '{print $2}')
if [ $status == "RUNNING" ]
then
echo "job is running!"
echo "getting jupyter information, hang tight.."
while :
do
if [ ! -f slurm-$jobid.out ]
then
echo "waiting for slurm output to be written"
let "wait+=1"
sleep 1s
elif [ $wait -gt 120 ]
then
echo "timed out waiting for output from job."
echo "check to make sure job didn't fail"
exit 0
else
check=$(cat slurm-$jobid.out | grep http://127.0.0.1 | wc -l)
if [ $check -gt 0 ]
then
echo "okay, now run the follwing on your local machine:"
echo $(cat slurm-$jobid.out | grep ssh)
echo "then, navigate to the following on your local browser:"
echo $(cat slurm-$jobid.out | grep http://127.0.0.1 | head -1 | awk {'print $5'})
exit 0
else
let "wait+=1"
sleep 1s
fi
fi
done
exit 0
elif [ $tries -gt 120 ]
then
echo "timeout.. terminating job."
scancel $jobid
exit 0
else
echo "job still pending.."
sleep 10s
fi
((tries++))
done