DEV Community

Cover image for How run background python scripts in Linux
Paulo Mota
Paulo Mota

Posted on

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

Top comments (0)