Laurent
Laurent

Reputation: 1

Running Python Script on Remote Server via SSH

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?

Upvotes: 0

Views: 6504

Answers (4)

haolee
haolee

Reputation: 937

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.

Upvotes: 4

Rohan
Rohan

Reputation: 5431

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.

Upvotes: 1

Pritam Pan
Pritam Pan

Reputation: 133

We use the following format to execute remote script ssh -t -t [email protected] 'nohup /path/to/scrip.py'

Upvotes: 0

viveksyngh
viveksyngh

Reputation: 787

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

Upvotes: 0

Related Questions