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 …


This content originally appeared on DEV Community and was authored by Paulo Mota

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


This content originally appeared on DEV Community and was authored by Paulo Mota


Print Share Comment Cite Upload Translate Updates
APA

Paulo Mota | Sciencx (2021-11-30T11:54:20+00:00) How run background python scripts in Linux. Retrieved from https://www.scien.cx/2021/11/30/how-run-background-python-scripts-in-linux/

MLA
" » How run background python scripts in Linux." Paulo Mota | Sciencx - Tuesday November 30, 2021, https://www.scien.cx/2021/11/30/how-run-background-python-scripts-in-linux/
HARVARD
Paulo Mota | Sciencx Tuesday November 30, 2021 » How run background python scripts in Linux., viewed ,<https://www.scien.cx/2021/11/30/how-run-background-python-scripts-in-linux/>
VANCOUVER
Paulo Mota | Sciencx - » How run background python scripts in Linux. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/30/how-run-background-python-scripts-in-linux/
CHICAGO
" » How run background python scripts in Linux." Paulo Mota | Sciencx - Accessed . https://www.scien.cx/2021/11/30/how-run-background-python-scripts-in-linux/
IEEE
" » How run background python scripts in Linux." Paulo Mota | Sciencx [Online]. Available: https://www.scien.cx/2021/11/30/how-run-background-python-scripts-in-linux/. [Accessed: ]
rf:citation
» How run background python scripts in Linux | Paulo Mota | Sciencx | https://www.scien.cx/2021/11/30/how-run-background-python-scripts-in-linux/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.