Linux 将 cron 选项卡设置为工作日的特定时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14436953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:44:54  来源:igfitidea点击:

setup cron tab to specific time of during weekdays

linuxcron

提问by Nauman Bashir

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?

工作日我应该做什么?

采纳答案by ThanksForAllTheFish

Same as you did for hours:

和你几个小时一样:

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

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

07代表星期日
6代表星期六
所以,1-5意思是从星期一到星期五

回答by EJW

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

回答by Fonant

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 不包括在内。