设置cron选项卡到工作日的特定时间

时间:2020-12-17 23:56:11

I am trying to setup a cron job on a Ubuntu server. We want the cron job to run the script at certain times of the day and on some specific days of the week. For example, we want to setup a cron job that runs the script with the following sequence:

我正在尝试在Ubuntu服务器上安装cron作业。我们希望cron作业在一天中的特定时间和一周中的特定时间运行脚本。例如,我们希望设置一个cron作业,该作业以以下顺序运行脚本:

Execute the script every 2 minutes from 9 am to 2 pm during the weekdays.

在工作日,从上午9点到下午2点每2分钟执行一次脚本。

This is what I have been able to do so far:

这是我迄今为止所能做到的:

*/2 09-14 * * * /path_to_script

*/2 09-14 * * * */ path_to_script

What should I do for the weekdays?

工作日我应该做什么?

3 个解决方案

#1


157  

Same as you did for hours:

和你几小时前做的一样:

*/2 09-18 * * 1-5 /path_to_script

0 and 7 stand for Sunday
6 stands for Saturday
so, 1-5 means from Monday to Friday

0和7代表星期天,6代表星期六,1-5代表星期一到星期五

#2


19  

You state 2pm in your requirement, hour range should end at 14 instead of 18 (which is 6pm).

你的要求是下午2点,工作时间应该在14点结束,而不是18点(也就是6点)。

*/2 9-14 * * 1-5 /path_to_script

man crontab

男人crontab

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab + 5

#3


11  

In fact the last hour you want the script to run is 13:00 to 13:59, so you want:

实际上,你希望脚本运行的最后一个小时是13:00到13:59,所以你想:

*/2 9-13 * * 1-5 /path_to_script

meaning the first runtime will be 9:00, then 9:02, and so on until 13:58 which will be the last run as 14:00 is not included.

这意味着第一个运行时将是9:00,然后是9:02,等等,直到13:58,这是最后一次运行,因为14:00不包括在内。

#1


157  

Same as you did for hours:

和你几小时前做的一样:

*/2 09-18 * * 1-5 /path_to_script

0 and 7 stand for Sunday
6 stands for Saturday
so, 1-5 means from Monday to Friday

0和7代表星期天,6代表星期六,1-5代表星期一到星期五

#2


19  

You state 2pm in your requirement, hour range should end at 14 instead of 18 (which is 6pm).

你的要求是下午2点,工作时间应该在14点结束,而不是18点(也就是6点)。

*/2 9-14 * * 1-5 /path_to_script

man crontab

男人crontab

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab + 5

#3


11  

In fact the last hour you want the script to run is 13:00 to 13:59, so you want:

实际上,你希望脚本运行的最后一个小时是13:00到13:59,所以你想:

*/2 9-13 * * 1-5 /path_to_script

meaning the first runtime will be 9:00, then 9:02, and so on until 13:58 which will be the last run as 14:00 is not included.

这意味着第一个运行时将是9:00,然后是9:02,等等,直到13:58,这是最后一次运行,因为14:00不包括在内。