-
Notifications
You must be signed in to change notification settings - Fork 0
/
forward_notebook.sh
executable file
·55 lines (43 loc) · 1.42 KB
/
forward_notebook.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
#!/bin/bash
# Written by Keith Harrigian / Nathaniel Weir
## Choose Port
PORT=6000
## Choose Path for Running the Noteboook and storing the job log
## Default is the current directory
NB_LOC="${PWD}"
GL="${NB_LOC}/logs"
mkdir -p "${GL}"
## Get Current Date for Logs
DATE=`date '+%Y-%m-%d-%H-%M-%S'`
## Log files
ERRFILE="${GL}notebook_${DATE}.out"
## Schedule the Job
sub_message=$(qsub -V -j y -o ${ERRFILE} "run_notebook.sh" ${PORT} ${NB_LOC})
job_id=$(echo ${sub_message} | awk '{print $3}')
## Wait For Job to Start Running
job_status=$(qstat | grep ${job_id} | awk '{print $5}')
while [[ ${job_status} != "r" ]]
do
qstat | grep ${job_id}
sleep 5
job_status=$(qstat | grep ${job_id} | awk '{print $5}')
done
## Sleep a bit To Let The Notebook Start Up
echo "Letting the notebook startup..."
sleep 5
## Identify Node Where Job is Running
node_address=$(qstat -u $USER | grep ${job_id} | awk '{print $8}')
node_address=${node_address#*@}
node_address=${node_address%%.*}
## Where is the Job Running
echo "Job Running on ${node_address}"
## Open SSH Tunnel
ssh -o "StrictHostKeyChecking=no" -Nf -L ${PORT}:localhost:${PORT} ${node_address}
status=$?
if [ $status -ne 0 ]
then
echo "Port forwarding from ${node_address}:{$PORT} failed. Check active processes with ps aux | grep ${USER[1:5]} "
fi
## Alert User
usr_alert="On local machine, run: ssh -L ${PORT}:localhost:${PORT} ${USER}@login.clsp.jhu.edu"
echo ${usr_alert}