From a1c8eab89a9cc5c5f555caef3d173adf9bec7461 Mon Sep 17 00:00:00 2001
From: Mike Boss <mboss@ethz.ch>
Date: Thu, 28 Apr 2022 10:57:34 +0200
Subject: [PATCH] Extend cleanup.sh

---
 cleanup.sh | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/cleanup.sh b/cleanup.sh
index 08e5772..7bfdcd6 100755
--- a/cleanup.sh
+++ b/cleanup.sh
@@ -1,5 +1,16 @@
 #!/bin/bash
 
-kill $(ps -u | grep -m1 -- "-L" | grep -- "-N" | awk '{print $2}')
+if [[ $# -lt 1 ]]
+then
+    echo -e "Error: No ETH username is specified, terminating script\n"
+    exit 1
+fi
 
-ssh -T $1@euler.ethz.ch bkill $(cat reconnect_info  | grep BJOB | awk '{print $NF}') 
\ No newline at end of file
+VSC_USERNAME=$1
+
+VSC_TUNNEL=$(cat reconnect_info | grep -o -E '[0-9]+:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+):[0-9]+')
+TUNNEL_JOBS=$(ps -u | grep $VSC_TUNNEL | grep ssh | awk '{ print $2 }')
+
+for TUNNEL_JOB in $TUNNEL_JOBS; do echo $TUNNEL_JOB; kill $TUNNEL_JOB; done
+
+ssh -T $VSC_USERNAME@euler.ethz.ch bkill $(cat reconnect_info  | grep BJOB | awk '{print $NF}') 
-- 
GitLab