ZZzzZZzz
ZZzzZZzz

Reputation: 1844

How to run Screen command on EC2 instance from Python script

I have tried launching a EC2 instance from pycharm using a Python script. As part of the launch process, I have downloaded a .sh script from s3 and have executed below commands.

commands = [
    "aws s3 cp s3://sample/test.sh /home/ubuntu/test.sh",
    "chmod +x /home/ubuntu/test.sh",
    "sudo apt-get update",
    "./test.sh"
]

However, when the last command './test.sh' is executed, I want to get out of the flow and create few more instances. But, as the script ./test.sh is a long running script, its not exiting the loop. I would like to submit the job as a background Screen job, but, was not able to open a screen using python code snippets. I am using paramiko module to connect to EC2 instance.

Upvotes: 1

Views: 3084

Answers (1)

ZZzzZZzz
ZZzzZZzz

Reputation: 1844

I have changed the above statement from ./test.sh to screen -d -m ./test.sh and it did the trick for me.

Upvotes: 3

Related Questions