Crontab or cron table is the list of tasks scheduled to run at regular time intervals on the system. Cron is a system daemon used to execute desired tasks (in the background) at designated times. You can use this to schedule activities, either as one-time events or as recurring tasks.
This is helpful to schedule a particular task that you want your server to execute after a fixed time period. Now the task could be as simple as restarting your server or doing a web-scrapping activity at a specific period of time.
Here, we will discuss how to setup your first Cron Jobs on AWS EC2.
a. First, log in to your AWS EC2 instance
b. Run the below command in your CLI
$ crontab -e
When you run Crontab command for the first time you will get an option to open using a editor.

Select option 2 (nano editor) and enter.
Now you will have your Cron Jobs open on your nano editor.
c. Add your every file paths/function paths which you want to schedule.
Note that you should specify single file path per line
Each entry in a crontab file consists of six fields, specifying in the following order: minute(s) hour(s) day(s) month(s) weekday(s) command(s)
For example:
0 11 * * * python3 /home/user/sample.py
Here we have specified to the crontab to run the specified python script – every day at 11:00 am.
5 stars are explained below:
1st *: Minute (ranges from 0-59)
2nd *: Hour (ranges from 0-23)
3rd *: Day (ranges from 1-31)
4th *: Month(ranges from 1-12)
5th *: Day-of-week (0-7. 0 & 7 is Sun. 1-Mon, 2-Tue…etc)
Step values can be used in conjunction with ranges. For example, “0-23/2” in the Hours field means “every other hour.” Steps are also permitted after an asterisk, so if you want to say “every two hours”, you can use “*/2“.
The crontab file
Each line of a crontab file is either “active” or “inactive”. An “active” line is an environment setting, or a cron command entry. An “inactive” line is anything ignored, including comments.
Blank lines and leading spaces and tabs are ignored. Lines whose first non-space character is a pound sign (#) are interpreted as comments, and are ignored. Comments are not allowed on the same line as cron commands, because they will be interpreted as part of the command. For the same reason, comments are not allowed on the same line as environment variable settings.
d. After you enter your Cron Job Commands you have to save it by pressing Cntrl+x and then select ‘Y’ and Enter.
Ta-da, now your Cron Job is set. Now to check whether your Cron Jobs is fine, run the below command.
$crontab -l
This will let you see your Cron Job file which has all your Cron Jobs including the new ones you just typed.
To test your schedule, set your cron job to execute after 5 minutes or so, this will give you plenty of time to change back the cron job to desired setting after testing.
Happy coding!