0
0
Linux CLIscripting~10 mins

crontab syntax in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - crontab syntax
Start
Read 5 time fields
Match current time with fields?
NoWait 1 minute
Yes
Run scheduled command
Wait 1 minute
Back to Read 5 time fields
Crontab reads five time fields, checks if current time matches, runs the command if yes, then waits for the next minute.
Execution Sample
Linux CLI
30 14 * * 1 /home/user/backup.sh
Runs backup.sh at 2:30 PM every Monday.
Execution Table
StepMinute FieldHour FieldDay of Month FieldMonth FieldDay of Week FieldCurrent TimeMatch?Action
13014**114:29 MondayNoWait
23014**114:30 MondayYesRun /home/user/backup.sh
33014**114:31 MondayNoWait
43014**114:30 TuesdayNoWait
💡 Crontab waits each minute, runs command only when all time fields match current time.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4
Current Time14:29 Monday14:29 Monday14:30 Monday14:31 Monday14:30 Tuesday
Match ResultNoNoYesNoNo
ActionWaitWaitRun /home/user/backup.shWaitWait
Key Moments - 3 Insights
Why does the command run only at 14:30 on Monday and not other times?
Because the minute field is 30, hour is 14, and day of week is 1 (Monday). Only when all match current time (see execution_table step 2) does the command run.
What does the asterisk (*) mean in the day of month and month fields?
An asterisk means 'any value'. So the command runs regardless of day of month or month, as long as other fields match (see execution_table).
If the day of week is set to 1, will the command run on Tuesday?
No, because day of week 1 means Monday only. On Tuesday, the match fails (see execution_table step 4), so the command does not run.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the action at step 3 when the time is 14:31 Monday?
ARun /home/user/backup.sh
BRun a different command
CWait
DExit crontab
💡 Hint
Check the 'Action' column at step 3 in the execution_table.
At which step does the command run according to the execution table?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look for 'Run /home/user/backup.sh' in the Action column.
If the minute field changed from 30 to 31, when would the command run?
AAt 14:30 Monday
BAt 14:31 Monday
CAt 14:29 Monday
DNever
💡 Hint
Match happens when current time matches all fields; see variable_tracker for Current Time values.
Concept Snapshot
Crontab syntax has 5 time fields: minute hour day_of_month month day_of_week
Each field can be a number or * (any).
Crontab runs the command when current time matches all fields.
Example: '30 14 * * 1' runs at 14:30 every Monday.
Use crontab to schedule repeated tasks easily.
Full Transcript
Crontab syntax uses five fields to schedule commands: minute, hour, day of month, month, and day of week. Each field can be a specific number or an asterisk meaning any value. The crontab checks every minute if the current time matches all fields. If yes, it runs the command. For example, '30 14 * * 1 /home/user/backup.sh' runs the backup script at 2:30 PM every Monday. If the time does not match, crontab waits and checks again the next minute. This way, you can automate tasks to run at specific times easily.