Skip to content

Commit 2a7d2ad

Browse files
committed
Script to start jupyter lab in tmux window
1 parent 5799c72 commit 2a7d2ad

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Shell script to start a Jupyter lab session
4+
# in a tmux window (so it persists even if ssh tunnel is disconnected)
5+
6+
red_start='\033[0;31m'
7+
blue_start='\033[0;34m'
8+
nocolor_start='\033[0m'
9+
10+
source /tmp/conda/bin/activate
11+
conda activate jupyter
12+
13+
# Start configuration for Jupyter lab
14+
echo "Enter password to access Jupyter lab from browser,"
15+
echo "or leave blank to not require a password."
16+
PW="$(python3 -c 'from jupyter_server.auth import passwd; import getpass; print(passwd(getpass.getpass(), algorithm="sha256"))')"
17+
jlab_start="jupyter Space lab Space --no-browser Space --autoreload Space --port=9889 Space --ip='127.0.0.1' Space --NotebookApp.token='' Space --NotebookApp.password=\"$PW\" Space --notebook-dir=\"~/ECCO-v4-Python-Tutorial/Tutorials_as_Jupyter_Notebooks\""
18+
19+
# Start new tmux session
20+
tmux new -d -s jupyterlab
21+
22+
# Execute commands in tmux window using send-keys
23+
tmux send-keys -t jupyterlab source Space /tmp/conda/bin/activate Enter
24+
tmux send-keys -t jupyterlab conda Space activate Space jupyter Enter
25+
tmux send-keys -t jupyterlab ${jlab_start} Enter
26+
27+
# Print info about tmux session
28+
echo -e "${red_start}Started Jupyter lab in tmux session jupyterlab"
29+
echo -e "${red_start}Access from your local machine in a browser window at"
30+
echo -e "${blue_start}http://127.0.0.1:9889/"
31+
echo -e "${red_start}tmux session can be accessed with"
32+
echo -e "${blue_start}tmux a -t jupyterlab"
33+
echo -e "${red_start}and terminated with"
34+
echo -e "${blue_start}tmux kill-ses -t jupyterlab${nocolor_start}"

0 commit comments

Comments
 (0)