First, boot automatically
If Python script from the start auto.py
. Then edit the file as root:
sudo vim /etc/rc.local
If you do not
rc.local
see this article
In the above command exit 0 edit the startup script
/usr/bin/python3 /home/selfcs/auto.py > /home/selfcs/auto.log
Finally restart Linux, the script will automatically run and print the log.
Second, let Python script timer start
Edit the following file as root
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 two minutes is performed once every script and print the log.
Three, crontab written explanation
The basic format
* * * * * user command
分 时 日 月 周 用户 命令
3.1 illustrates
1, performed once per minute
* * * * * user command
2, performed once every 2 hours
* */2 * * * user command (/表示频率)
3, 8:30 pm executed once a day
30 8 * * * user command
4, 30 and 50 minutes per hour executed once
30,50 * * * * user command(,表示并列)
5, 8:30 execution to No. 3 on the 6th of each month once
30 8 3-6 * * user command (-表示范围)
6, every Monday at 8:30 execution of a
30 8 * * 1 user command (周的范围为0-7,0和7代表周日)