Setting up Cron Jobs on AWS EC2

Cron Jobs are scheduled tasks running at a specified frequency.

In the AWS EC2/ dedicated server, we have to set up the cron using CLI (with root login access).

Steps to setup Cron Jobs on AWS EC2:
1. Log in to your AWS EC2 using CLI/SSH.
2. Run the following command
# crontab -e

Please note, while running Crontab command for the first time you will see the option to choose your editor like this:
Choose 1-4?

3. Choose your favorite editor and hit Enter. It will open the editor selected by you.

4. Add path of your function, for which you want to setup the cron like this:
0 * * * * php /var/www/public_html/cronjobs/sendnewsletter.php
0 * * * * /bin/php /var/www/public_html/cronjobs/sendnewsletter.php
0 * * * * wget X.X.X.X/cronjobs/sendnewsletter.php

First term “0 * * * *” is Cron expression.
Second term “php or /bin/php or wget” is command/path. The command path will change depends on the programming language.
The third term is the file Path.

5. After entering the cron job command, you have to save it.
6. To check the list of running Cron Jobs, run the below command.
# crontab -l