-
Notifications
You must be signed in to change notification settings - Fork 0
/
jupyter.bash
executable file
·41 lines (30 loc) · 1 KB
/
jupyter.bash
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
#!/bin/bash
USERNAME=$1
OS_TYPE=$(uname)
if [ $# -eq 0 ]; then
echo "Please pass your USERNAME as the argument"
exit
fi
CMD1="jupyter-notebook --no-browser --port=7777 &"
CMD2="ssh -N -f -L localhost:7777:localhost:7777 [email protected]"
# ssh to Anvil, and check if a jupyter notebook is
# already running under your name
var=$(ssh [email protected] ps -ef | grep jupyter | grep $USERNAME | awk '{print $1, $11}')
# If jupyter is not running, start a new notebook and background it
if [ -z "$var" ]; then
echo Starting a jupyter notebook
ssh -f [email protected] $CMD1
fi
# Open a new terminal, and create a ssh tunnel
# Kill any localhost process runnig on port 7777
pkill -f localhost
xterm -e $CMD2
# Open web browser on localhost and port 7777
# Check OS type first
if [ $OS_TYPE == 'Darwin' ]; then
open http://localhost:7777
elif [ $OS_TYPE == 'Linux' ]; then
xdg-open http://localhost:7777
else
echo Open your local browser, and type \"localhost:7777\"
fi