-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtunnel.sbatch
62 lines (47 loc) · 1.4 KB
/
tunnel.sbatch
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
#!/bin/bash
#SBATCH --job-name=tunnel
#SBATCH --nodes=1
#SBATCH --ntasks=1
#
# Slurm Job Tunnel
#
# Copyright (c) 2024 by Wiep K. van der Toorn
#
# Usage example:
# $ sbatch --time=120 --mem=8G --qos=hiprio --cpus-per-task=8 tunnel.sbatch
#
# Attention: time should be set in minutes!
#
echo "
###########################################
SLURM variables
###########################################
SLURM_JOB_START_TIME=${SLURM_JOB_START_TIME}
SLURM_JOB_END_TIME=${SLURM_JOB_END_TIME}
###########################################
"
echo "
SIF_BIND_PATH used for singularity bindings: ${SIF_BIND_PATH}
"
# Get tunneling information
XDG_RUNTIME_DIR=""
NODE=$(hostname -s)
PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()') # random available port
# Tunneling instructions
echo "
Will open tunnel to:
NODE=${NODE}
PORT=${PORT}
"
# Calculate the time limit in minutes from SLURM_JOB_START_TIME and SLURM_JOB_END_TIME
TIME=$(date -u -d @$(( $SLURM_JOB_END_TIME - $SLURM_JOB_START_TIME )) +%H:%M:%S)
end_time_readable=$(date -d "@$SLURM_JOB_END_TIME" '+%Y-%m-%d %H:%M:%S')
echo "
The time limit for this job is: $TIME
This tunnel will close at: $end_time_readable
"
if [ -n "${SIF_BIND_PATH}" ]; then
singularity exec -B ${SIF_BIND_PATH}:${SIF_BIND_PATH} ${SIF_IMAGE} /usr/sbin/sshd -p ${PORT} -D
else
singularity exec ${SIF_IMAGE} /usr/sbin/sshd -p ${PORT} -D
fi