1. Python automatically runs at startup Suppose the Python self-starting script is sudo vim /etc/rc.local If you don't have Edit the command to start the script above exit 0 /usr/bin/python3 /home/selfcs/auto.py > /home/selfcs/auto.log Finally, restart Linux and the script will run automatically and print logs. 2. Start the Python script regularly Edit the following file with root privileges sudo vim /etc/crontab Add the following command at the end of the file 2 * * * * root /usr/bin/python3 /home/selfcs/auto.py > /home/selfcs/auto.log The above code means that the script will be executed every two minutes and the log will be printed. 3. Crontab Writing Explanation Basic format * * * * * user command Time-sharing, daily, monthly and weekly user commands 3.1 Example 1: Execute once every minute * * * * * user command 2. Execute every 2 hours * */2 * * * user command (/ indicates frequency) 3. Execute once every day at 8:30 30 8 * * * user command 4. Execute once at 30 and 50 minutes of every hour 30,50 * * * * user command (, indicates parallel) 5. Execute once at 8:30 on the 3rd to 6th of each month 30 8 3-6 * * user command (- indicates range) 6. Execute once every Monday at 8:30 30 8 * * 1 user command (the range of the weekday is 0-7, 0 and 7 represent Sunday) Summarize The above is the detailed steps for the self-start and scheduled startup of Python scripts under Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: How to use a field in one table to update a field in another table in MySQL
>>: JS implements a simple brick-breaking pinball game
Because a certain function of my project requires...
DIV background is semi-transparent, but the words ...
Table of contents Preface Component Introduction ...
This article mainly introduces an example of impl...
A Textbox with Dropdown allows users to select an...
This article uses an example to describe how MySQ...
1. Basic Environment 1. Operating system: CentOS ...
Preface Learn MySQL to reorganize previous non-MK...
First, I will give you the VMware 14 activation c...
Table of contents Overview What are callbacks or ...
Precondition: content="width=750" <m...
This article uses an example to describe how to s...
The uniapp applet will have a similar drop-down p...
This article is from the Apache Spark Meetup held...
This article example shares the specific code of ...