Crontab Options for Running a Script on Monday Every Hour | Exam XK0-004

Crontab Options for Running a Script on Monday Every Hour

Question

A junior systems administrator is creating a cron job.

The cron job requirements are as follows: -> Run the hello.sh script every hour (24 times in one day)

-> Run it on Monday only.

Given this scenario, which of the following crontab options should be configured to meet these requirements?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

A.

The correct answer is option A: 0 *** 1 hello.sh.

Explanation:

Cron is a time-based job scheduler in Unix/Linux systems. It allows users to schedule jobs (commands or scripts) to run at specific intervals or times. Cron uses a special syntax for specifying the timing of jobs in the crontab file.

In the given scenario, the requirements are to run the hello.sh script every hour (24 times in one day) and only on Monday. The crontab options that need to be configured to meet these requirements are:

minute - Hour - Day of the Month - Month - Day of the Week - Command to execute

The asterisk (*) character is a wildcard and indicates "every."

Option A: 0 *** 1 hello.sh

  • The minute field is set to 0, meaning the job will run at the start of the hour.
  • The hour field is set to *, indicating that the job should run every hour.
  • The day of the month field is also set to *, indicating that the job should run every day of the month.
  • The month field is not specified, so the job will run every month.
  • The day of the week field is set to 1, which represents Monday.
  • The command to execute is "hello.sh".

Therefore, option A meets the requirements of running the hello.sh script every hour (24 times in one day) and only on Monday.

Option B: 0 24 ** Monday hello.sh

  • The minute field is set to 0, indicating the job will run at the start of the hour.
  • The hour field is set to 24, which is an invalid value as it only ranges from 0-23.
  • The day of the month field is set to **, which is also an invalid value.
  • The month field is not specified, so the job will run every month.
  • The day of the week field is set to Monday.
  • The command to execute is "hello.sh".

Option C: 24 *** Monday hello.sh

  • The minute field is set to 24, which is an invalid value as it only ranges from 0-59.
  • The hour field is not specified, so the job will not run.
  • The day of the month field is set to *, indicating that the job should run every day of the month.
  • The month field is not specified, so the job will run every month.
  • The day of the week field is set to Monday.
  • The command to execute is "hello.sh".

Option D: 1 *** 0 hello.sh

  • The minute field is set to 1, which is an invalid value as it only ranges from 0-59.
  • The hour field is not specified, so the job will not run.
  • The day of the month field is set to *, indicating that the job should run every day of the month.
  • The month field is not specified, so the job will run every month.
  • The day of the week field is set to 0, which represents Sunday.
  • The command to execute is "hello.sh".

Therefore, options B, C, and D do not meet the requirements of the given scenario.