0

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.

ABot
  • 197
  • 12
  • 3
    use full pathname to invoke jupyter: `ssh host "cd /path/to/my/folder/; /path/to/jupyter notebook"` – pynexj Jul 11 '19 at 10:19
  • @pynexj What do you mean by using the full pathname to invoke jupyter? The jupyter notebooks are in my folder. I tried adding an explicit jupyter file ```cd /path/to/my/folder/; jupyter notebook MyFile.ipynb```, I tried ```jupyter notebook /path/to/my/folder/MyFile.ipynb``` - all with the same results as described as above. I rather suspect, that jupyter is not added to the bash commands and I need to add it somewhere, just don't know where. – ABot Jul 11 '19 at 11:09
  • 2
    jupyter must be installed somewhere on your system, just like `ls` is usually `/bin/ls`. run `which jupyter` in your interactive shell and it'll output the full pathname for you. – pynexj Jul 11 '19 at 11:13
  • Thanks @pynexj , this works like a charm! If you add your comment as an answer I will mark it as successful. – ABot Jul 11 '19 at 11:21

0 Answers0