crontab 每隔5分钟执行一次,但是第一次执行需要从0点开始
其实就是执行的时间分别为0点 0点5分 这样依次进行。
对crontab不是很熟悉,不知道该怎么写
伊谢尔伦2017-04-17 11:49:13
*/5 0 * * * /bin/sh test.sh
Execute the script every 5 minutes starting from 0 o'clock
巴扎黑2017-04-17 11:49:13
The request of the question subject is The first execution starts from 0 o'clock and then stops. Okay, I didn’t understand it before, now here is a solution to start crontab regularly.
In addition to editing with crontab -e
, you can also directly place files in the /etc/cron.d
directory to achieve the same effect. The files in the cron.d directory are somewhat different from the crontab -e
files. You need to specify the user name used to execute the script before your-script
.
For example: /etc/cron.d/foo
# m h dom mon dow user command
*/5 * * * * root your-script
After having this preparatory knowledge, the only thing left is to write an ordinary crontab or other timer, let it put foo
at 11:56~11:59 on a certain day Just enter the /etc/cron.d
directory.
黄舟2017-04-17 11:49:13
Write a script that is executed at 23:56 at night. It adds the information about executing another script every five minutes to the crontab (and then deletes its own). (Or you can use the at command to add it, no need to delete it.)
Or, if possible, just write a systemd.timer unit.
高洛峰2017-04-17 11:49:13
A simple way is to write a scheduled task that is executed every minute. Then perform more complex logical judgment processing in this script that is executed every minute.