How to write python timed execution script under Linux
Most people do not understand the knowledge points of this article, "how to write a regular script for python under Linux", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to write a script for python timing under Linux".
1. Python starts up and runs automatically
If the Python self-startup script is auto.py. Then edit the following files with root privileges:
Sudo vim / etc/rc.local
❝
If there is no rc.local, please read this article.
The command to edit the startup script on exit 0
/ usr/bin/python3 / home/selfcs/auto.py > / home/selfcs/auto.log
Finally, restart Linux, and the script can run and print the log automatically.
Second, let the Python script start regularly
Edit the following files with root permissions
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 is executed every two minutes and the log is printed.
III. Crontab compiles explanations
Basic format
* user command time-sharing, day, month and week user command
3.1 give an example
1. Execute once every minute
* user command
2. Execute every 2 hours
* * / 2 * user command (/ represents frequency)
3. It is executed at 8:30 every day.
30 8 * user command
4. 30 minutes and 50 minutes per hour are executed respectively.
3050 * user command (, which means juxtaposition)
5. It is executed at 8:30 from the 3rd to the 6th of each month.
30 8 3-6 * * user command (- indicates range)
6. It is executed every Monday at 8:30
308 * * 1 user command (the range of weeks is 0-7 user command 0 and 7 represent Sundays). The above is about "how to write a regular script for python under Linux". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please follow the industry information channel.