From 833f14196da1e52c8ba9a87e53599befac3f40ec Mon Sep 17 00:00:00 2001 From: Mike Boss <mboss@ethz.ch> Date: Mon, 25 Apr 2022 14:50:35 +0200 Subject: [PATCH] Save jobid in variable by saving to file temporarily --- start_vscode.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/start_vscode.sh b/start_vscode.sh index fdde34a..ed0e972 100755 --- a/start_vscode.sh +++ b/start_vscode.sh @@ -297,8 +297,8 @@ ENDSSH # run the code-server job on Euler and save the ip of the compute node in the file vscip in the home directory of the user on Euler echo -e "Connecting to $VSC_HOSTNAME to start the code-server in a batch job" -# FIXME: save jobid in a variable, that the script can kill the batch job at the end -ssh $VSC_SSH_OPT bsub -n $VSC_NUM_CPU -W $VSC_RUN_TIME -R "rusage[mem=$VSC_MEM_PER_CPU_CORE]" $VSC_SNUM_GPU <<ENDBSUB + +ssh $VSC_SSH_OPT bsub -n $VSC_NUM_CPU -W $VSC_RUN_TIME -R "rusage[mem=$VSC_MEM_PER_CPU_CORE]" $VSC_SNUM_GPU > BJOB_ID_FILE<<ENDBSUB module load $VSC_MODULE_COMMAND export XDG_RUNTIME_DIR="\$HOME/vsc_runtime" VSC_IP_REMOTE="\$(hostname -i)" @@ -306,6 +306,9 @@ echo "Remote IP:\$VSC_IP_REMOTE" >> /cluster/home/$VSC_USERNAME/vscip code-server --bind-addr=\${VSC_IP_REMOTE}:8899 ENDBSUB +BJOB_ID=$(cat BJOB_ID_FILE | awk '{print $2}'| sed 's/[><]//g') +rm BJOB_ID_FILE + # wait until batch job has started, poll every $VSC_WAITING_INTERVAL seconds to check if /cluster/home/$VSC_USERNAME/vscip exists # once the file exists and is not empty the batch job has started ssh $VSC_SSH_OPT <<ENDSSH @@ -354,6 +357,7 @@ Remote port : $VSC_REMOTE_PORT Local port : $VSC_LOCAL_PORT SSH tunnel : ssh $VSC_SSH_OPT -L $VSC_LOCAL_PORT:$VSC_REMOTE_IP:$VSC_REMOTE_PORT -N & URL : http://localhost:$VSC_LOCAL_PORT +BJOB ID : $BJOB_ID EOF # setup SSH tunnel from local computer to compute node via login node -- GitLab