How run background python scripts in Linux

phmota

Paulo Mota

Posted on November 30, 2021

How run background python scripts in Linux

Let a python script running in linux server with no worries

It's simple just open your terminal in Linux and use the command and close the terminal

nohup python3 -u yourpythonfile.py > out.out

the argument "> out.out" will create the log file in the same folder that you run that command and when you open the terminal again to check how is the script you can use this command:

nano out.out

Now if you are using Google Cloud or AWS virtual machines, and you would like to shut down the machine after the execution to avoid extra costs $$ you can use this command:

nohup bash -c python3 -u yourpythonfile.py ; sudo shutdown -h now > out.out &

Image description

💖 💪 🙅 🚩
phmota
Paulo Mota

Posted on November 30, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related