0% found this document useful (0 votes)
14 views4 pages

Cron Tab

The document provides a comprehensive overview of the Crontab utility, detailing its format and usage for scheduling automated tasks in Unix-based systems. It includes examples of crontab entries, explanations of their components, and a series of multiple-choice questions to test understanding. Additionally, it notes that Crontab does not support scheduling at the second level.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Cron Tab

The document provides a comprehensive overview of the Crontab utility, detailing its format and usage for scheduling automated tasks in Unix-based systems. It includes examples of crontab entries, explanations of their components, and a series of multiple-choice questions to test understanding. Additionally, it notes that Crontab does not support scheduling at the second level.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Mastering in Cron Tab yogeshdixit29@gmail.

com
Article by – Yogesh dixit

Crontab is a Unix-based utility that allows users to schedule jobs to run automatically at
specified intervals. It's particularly useful for automating system maintenance tasks,
backups, and other repetitive activities.

### Crontab Format###

A crontab file contains lines with the following format:

* * * * * command_to_execute

The five asterisks represent:

1. Minute (0-59)

2. Hour (0-23)

3. Day of Month (1-31)

4. Month (1-12)

5. Day of Week (0-7) (Sunday is both 0 and 7)

You can set cronjob on multi specific minutes,hour, DOM and month using comma separated (,) or
using hyphen (-).

Suppose want to run cron on 25 or 31 min in every hour then cron will be like "25,31 * * * *".

If 25 to 31 minutes then "25-31 * * * *"

### Example####

- 0 5 * * * /path/to/script.sh - Runs the script at 5:00 AM every day.

- */10 * * * * /path/to/script.sh - Runs the script every 10 minutes.

### Answer the below MCQs###

1. What does the first asterisk in a crontab entry represent?

- A) Hour

- B) Minute

- C) Day of Month
- D) Day of Week

2. Which of the following crontab entries runs a job every day at midnight?

- A) 0 0 * * *

- B) * * * * *

- C) 0 12 * * *

- D) 0 0 * * 1

3. What does */5 * * * * mean in a crontab?

- A) Runs every 5 hours

- B) Runs every 5 days

- C) Runs every 5 minutes

- D) Runs every 5 seconds

4. In crontab, what does the entry 0 22 * * 1-5 do?

- A) Runs at 10 PM on weekends

- B) Runs at 10 PM on weekdays (Monday to Friday)

- C) Runs at 10 AM on weekdays

- D) Runs at midnight on weekdays

5. Which command is used to edit the crontab for the current user?

- A) crontab -e

- B) crontab -l

- C) crontab -r

- D) crontab -x

6. Which command is used to remove the crontab for the current user?

- A) crontab -e

- B) crontab -l

- C) crontab -r

- D) crontab –x
7. Suppose If Cron is like "*/3 */8 * * 1-2,2 command to execute" how many times it will run in a
week?

- A) 320 times

- B) 120 times

- C) 60 times

- D) 160 times

Write the answer of 7th question in comments.

8. What does the crontab entry 15 14 1 * 5 mean?

- A) Run at 2:15 PM on the first day of each month, but only if it's a Friday.

- B) Run at 2:15 PM every Friday.

- C) Run at 2:15 PM on the first day of each month, regardless of the day of the week.

- D) Run every Friday at 2:15 PM.

9. Which of the following entries will run a job every day at 6:00 AM and 6:00 PM?

- A) 0 6,18 * * *

- B) 0 6 * * */18

- C) 0 6,18 * * 1-5

- D) 0 6-18 * * *

10. How many times will the job */5 2,3 * * 1-5 run in a week?

- A) 560

- B) 568

- C) 576

- D) 10

11. What will the crontab entry 0 0 1 1 * do?

- A) Run at midnight every day.

- B) Run at midnight on the first day of each month.

- C) Run at midnight on the first day of the year.


- D) Run at midnight every January.

12. What does the entry @reboot /path/to/script.sh do?

- A) Runs the script every hour.

- B) Runs the script at system startup.

- C) Runs the script when the cron daemon starts.

- D) Runs the script at midnight.

12. Which of the following entries will run a job every 15 minutes during business hours (9 AM to 5
PM) on weekdays?

- A) */15 9-17 * * 1-5

- B) 0,15,30,45 9-17 * * 1-5

- C) Both A and B

- D) */15 9-17 * * *

Note- Crontab does not support specifying seconds in its scheduling syntax. If you need to schedule
tasks at the second level. You can use sleep or systemd timer.

Answer1: B) Minute

Answer2: A) 0 0 * * *

Answer3:C) Runs every 5 minutes

Answer4: B) Runs at 10 PM on weekdays (Monday to Friday)

Answer5: A) crontab -e

Answer6: C) crontab -r

Answer8: A) Run at 2:15 PM on the first day of each month, but only if it's a Friday

Answer9: A) 0 6,18 * * *

Answer10: C) 576

Answer11:C) Run at midnight on the first day of the year.

Answer12: B) Runs the script at system startup.

Answer13:C) Both A and B are correct

You might also like