user2174397
user2174397

Reputation: 11

How to exectute a Mathematica Script through ssh

here is my problem: i would like to run a Mathematica script through ssh on a remote machine so that i can close the terminal on my computer and keep it running on the remote one.

My problem arises because the script acts in interacting mode, and so when i close the terminal the process is shut down too.

Thanks.

Upvotes: 1

Views: 2470

Answers (2)

Derek
Derek

Reputation: 3355

Several cases:

  • If you don't need to interact with it or need to visualize the notebook during evaluation

    1. Log in to the machine with ssh
    2. Then, to run a kernel in the background and detach it from the current session, use nohup tool (the standard output of the command will be dumped to myNotebook.out):

      nohup math < myNotebook.nb > myNotebook.out &
      
    3. At this point, the ssh session can be closed without killing Mathematica
    4. Optionally you can monitor mathcommand output with the tail command (use CTRL-C to exit the tail monitoring)

      tail -f myNotebook.out
      
  • If you need to see what's going on, visualize graphs during calculation or to be able to interact graphically, use remote desktop (vnc) and tunnel your communication with remote machine. Details depends a bit on the Linux distribution (vnc clients & servers may differ). You can even from Windows or Mac connect with remote desktop to your linux box and manipulate it. I suggest you to search the web for remote desktop ssh tunnel + your distro for tutorials.

Upvotes: 1

dave4420
dave4420

Reputation: 47062

Use tmux or GNU screen.

Workflow:

  • ssh into remote machine
  • start tmux/screen, e.g. tmux or screen
  • start Mathematica script inside tmux/screen session
  • detach tmux/screen session, e.g. Ctrl+B d (tmux) or Ctrl+A d (screen)
  • close ssh connection

Then later:

  • ssh into remote machine
  • reattach to tmux/screen session, e.g. tmux attach or screen -d -R
  • view completed Mathematica script output

Upvotes: 3

Related Questions