Added jupyter link printing
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Script to extract where is the jupyter session running by parsing the log file
|
||||
# This is useful when re-loging to the same node or if one misses it when the new jupyter session is initiated with start_jupyter.sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
LOGFILE=$(
|
||||
find "$HOME" -maxdepth 1 -type f -name "jupyterlab_*.log" -printf "%T@ %p\n" 2>/dev/null \
|
||||
| sort -n \
|
||||
| awk '{print $2}' \
|
||||
| tail -n 1
|
||||
)
|
||||
|
||||
if [[ -z "${LOGFILE:-}" || ! -f "$LOGFILE" ]]; then
|
||||
echo "No jupyterlab_*.log found in $HOME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Slurp the whole logfile and try multiple patterns.
|
||||
perl -0777 -ne '
|
||||
my $s = $_;
|
||||
$s =~ s/\r//g;
|
||||
$s =~ s/\n/ /g;
|
||||
|
||||
# 1) Direct URL that already contains token=
|
||||
if ($s =~ m{(https?://[^\s"'"'"']+\?token=[^\s"'"'"'&]+)} ) {
|
||||
print "$1\n"; exit 0;
|
||||
}
|
||||
if ($s =~ m{(https?://[^\s"'"'"']+/lab\?token=[^\s"'"'"'&]+)} ) {
|
||||
print "$1\n"; exit 0;
|
||||
}
|
||||
if ($s =~ m{(https?://[^\s"'"'"']+/tree\?token=[^\s"'"'"'&]+)} ) {
|
||||
print "$1\n"; exit 0;
|
||||
}
|
||||
|
||||
# 2) URL and token appear separately (wrapped / split)
|
||||
my ($base) = ($s =~ m{(https?://[^\s"'"'"']+)}); # first URL-looking thing
|
||||
my ($token) = ($s =~ m{token=([A-Za-z0-9]+)}); # token value
|
||||
if ($base && $token) {
|
||||
# Ensure we don’t end up with double ?token
|
||||
$base =~ s/\?token=.*$//;
|
||||
print $base . "?token=" . $token . "\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
exit 1;
|
||||
' "$LOGFILE" || {
|
||||
echo "Could not find a Jupyter token link in:"
|
||||
echo " $LOGFILE"
|
||||
echo
|
||||
echo "Try:"
|
||||
echo " grep -n -E \"token=|http://|https://\" \"$LOGFILE\" | head -n 80"
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user