SSH [SOLVED]: Keep running a python script on AWS EC2 even if CLI session is closed

SSH [SOLVED]: Keep running a python script on AWS EC2 even if CLI session is closed

Home Forums SSH SSH [SOLVED]: Keep running a python script on AWS EC2 even if CLI session is closed

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36062

    Anonymous

    QuestionQuestion

    so I have a script running on (script is inside the instance) my AWS EC2 instance (Ubuntu), which should write some results of benchmarks into a txt file (also in the instance itself) every few hours…Now I have run the session with my terminal and ssh, but if I close my terminal or shut down my computer, the script obviously crashes.
    I have even tried: “nohup myscript.py &”, but without any success.

    Would really appreciate some help here

    #36063

    Anonymous

    Accepted AnswerAnswer

    In my opinion the easiest way is to install one of existing terminal multiplexers like screen or tmux and run your script inside this multiplexer. This will allow your script to run even after disconnecting from shell session.

    Please keep in mind that shutting down AWS EC2 machine also kills screen/tmux session and your script won’t be restored after starting that machine again. However after detaching from screen/tmux session on remote machine you can safely close or restart your local computer, reconnect after several hours or days or even years and your remote session with your script inside should still exist (as long as AWS EC2 machine wasn’t restarted or your screen/tmux session wasn’t closed manually be administrator for example).

    Source: https://stackoverflow.com/questions/47823240/keep-running-a-python-script-on-aws-ec2-even-if-cli-session-is-closed
    Author: running.t
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.