LFCS · Question #765
The correct crontab entry to execute the script chklog once per hour between 3 p.m. and 5 p.m. on Monday and Thursday each week is:
The correct answer is C. 0 15,16,17 * * 1,4 chklog. The crontab entry must specify 0 for minutes, 15, 16, 17 for hours (3, 4, 5 PM in 24-hour format), and 1, 4 for Monday and Thursday respectively.
Question
Options
- A0 3,4,5 * * 2,5 chklog
- B0 3,4,5 * * 1,4 chklog
- C0 15,16,17 * * 1,4 chklog
- D0 15,16,17 1,4 * * chklog
- E
- 15,16,17 * * 1,4 chklog
How the community answered
(27 responses)- A4% (1)
- C70% (19)
- D19% (5)
- E7% (2)
Why each option
The crontab entry must specify 0 for minutes, 15, 16, 17 for hours (3, 4, 5 PM in 24-hour format), and 1, 4 for Monday and Thursday respectively.
`3,4,5` for hours would represent 3 AM, 4 AM, 5 AM, not 3 PM to 5 PM, and `2,5` for day of week would be Tuesday and Friday.
`3,4,5` for hours would represent 3 AM, 4 AM, 5 AM, not 3 PM to 5 PM.
The crontab syntax is `minute hour day_of_month month day_of_week command`. `0` specifies the task runs at the top of the hour. `15,16,17` specifies 3 PM, 4 PM, and 5 PM (24-hour format). `*` for day_of_month and month means every day/month, and `1,4` specifies Monday (1) and Thursday (4), typically with Sunday being 0 or 7.
The day of week (1,4) is incorrectly placed in the day of month field, and the month and day of week fields are swapped, leading to an incorrect schedule.
`*` for minutes would run the script every minute during the specified hours, not once per hour.
Concept tested: Crontab syntax and scheduling
Source: https://man7.org/linux/man-pages/man5/crontab.5.html
Topics
Community Discussion
No community discussion yet for this question.