nerdexam
CompTIA

XK0-004 · Question #430

A Linux administrator needs to schedule a backup job to run every Friday at 2:15 a.m. Which of the following lines should the administrator add to the crontab file?

The correct answer is A. 15 2 * * 5 /bin/backup_job.sh. Cron field order is minute, hour, day-of-month, month, day-of-week, so 2:15 a.m. every Friday is represented as '15 2 5'.

Scripting, Containers and Automation

Question

A Linux administrator needs to schedule a backup job to run every Friday at 2:15 a.m. Which of the following lines should the administrator add to the crontab file?

Options

  • A15 2 * * 5 /bin/backup_job.sh
  • B2 15 * * 5 /bin/backup_job.sh
  • C2 * * 15 5 /bin/backup_job.sh
  • D2 * 5 15 * /bin/backup_job.sh

How the community answered

(25 responses)
  • A
    92% (23)
  • B
    4% (1)
  • D
    4% (1)

Why each option

Cron field order is minute, hour, day-of-month, month, day-of-week, so 2:15 a.m. every Friday is represented as '15 2 * * 5'.

A15 2 * * 5 /bin/backup_job.shCorrect

The crontab format follows the order: minute hour day-of-month month day-of-week command. '15 2 * * 5' means minute 15, hour 2 (2 a.m.), any day of month, any month, and day-of-week 5 (Friday), which precisely matches the requirement of 2:15 a.m. every Friday.

B2 15 * * 5 /bin/backup_job.sh

This places 2 in the minute field and 15 in the hour field, which would schedule the job at 3:02 a.m. (15:02 in 24-hour terms is not 2:15 a.m.), reversing the minute and hour values.

C2 * * 15 5 /bin/backup_job.sh

This places values in incorrect fields - day-of-month and month positions are swapped with the time values, resulting in an invalid or unintended schedule.

D2 * 5 15 * /bin/backup_job.sh

This format misplaces the day-of-week value into the day-of-month field and leaves other fields as wildcards, which would not correctly target Fridays at 2:15 a.m.

Concept tested: Crontab syntax for scheduling jobs by time and weekday

Source: https://man7.org/linux/man-pages/man5/crontab.5.html

Topics

#crontab#cron syntax#job scheduling#task automation

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice