I'm a lazy person and would like to create a shortcut for a very repetitive task: I would like to write a (bash) script, that 1. Connects to a remote server 2. navigates to the correct folder 3. Starts a jupyter notebook there
I'm on ubuntu as is the server (18.04.2 LTS) and would preferably have a bash script or an alias to do these three steps for me.
What I usually have to do is:
me@mymachine:~$ ssh hostname@xxx.xx.xxx.xxx
hostname@xxx.xx.xxx.xx's password:
...
Last login: Thu Jul 11 11:26:47 2019 from xxx.xx.xxx.xxx
(base) hostname@host:~$ cd /path/to/my/folder/
(base) hostname@host:~$ jupyter notebook --no-browser --ip xxx.xx.xxx.xxx
...
To access the notebook, open this file in a browser:
file:///run/user/1000/jupyter/nbserver-21110-open.html
Or copy and paste one of these URLs:
http://xxx.xx.xxx.xxx:8889/?token=111222333444555666sometoken888999
Which I use to open the jupyter notebook in my browser of choice.
What I have tried so far:
#!/bin/bash
ssh hostname@xxx.xxx.xxx.xx "cd /path/to/my/folder/; jupyter notebook"
Which results in
hostname@xxx.xx.xxx.xxx's password:
bash: jupyter: command not found
I suspect I need to add the jupyter command to the .bashrc or something similar? I couldn't find a definite answer and don't want to play around with this.
Alternatively I tried
#!/usr/bin/expect -f
spawn ssh hostname@xxx.xx.xxx.xxx
expect "assword:"
send "mypassword\r"
(taken from here! and here!) But then I don't know how to combine this with the navigation to the right location and opening of the jupyter notebook.