Detailed steps of self-startup and timing startup of Python script 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 examples 1. Execute once per 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
30 8 * 1 user command (the range of weeks is 0-7. 0 and 7 represent Sundays)
Summary
The above is the detailed steps of self-startup and timing startup of Python script under Linux introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!
If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!