0

I am trying to run this Python Script on a Digital Ocean (DO) Droplet (Ubuntu 16): https://github.com/instabot-py/instabot.py

Although I can run python3 example.py the process stops if I kill the Terminal windown I used to SSH into the DO Droplet.

Is there a way to run this Python script and disconnect from the DO Droplet with the Python script still running?

Rohan
  • 5,121
  • 1
  • 17
  • 19
Laurent
  • 1
  • 1
  • 2
  • https://askubuntu.com/questions/8653/how-to-keep-processes-running-after-ending-ssh-session – Rohan Jul 31 '17 at 03:29
  • 1
    Possible duplicate of [Keep SSH Sessions running after disconnection - for overnight](https://stackoverflow.com/questions/33205456/keep-ssh-sessions-running-after-disconnection-for-overnight) – Rohan Jul 31 '17 at 03:34

4 Answers4

4

Use nohup to run program in background

nohup python3 example.py > /dev/null 2>&1 &

Or you can use screen to do this:

$ screen
$ python3 example.py
To detach the current session, you can press Ctrl+A and then press D.
To re-attach previous session, use command `screen -r`

The screen command is more powerful than nohup.

haolee
  • 892
  • 9
  • 19
1

You can use screen in linux to continue executing the process in background even after you disconnect from server. Similarly tmux can be used.

The answer to this question is most probably what you are looking for.

Rohan
  • 5,121
  • 1
  • 17
  • 19
0

You can try these python library to achieve this

http://www.paramiko.org/

https://pypi.python.org/pypi/spur

Or you can also use tmux to run command on remote server and your tmux seisson will run in the background even if you quit the shell. You can join that tmux session even after days and continue executing command

viveksyngh
  • 777
  • 7
  • 15
0

We use the following format to execute remote script ssh -t -t user@host.com 'nohup /path/to/scrip.py'

Pritam Pan
  • 133
  • 7