Setting up cron jobs on a server is a task that can be either notoriously easy or difficult. I've set some up that have taken 30 seconds, from start to finish. Some others, I've never figured out. If you've got a straightforward command, such as triggering a file to run, it shouldn't take you much time at all, especially if you configure the cron through cPanel. And just to be clear, it's not the time settings that can be challenging, it's the command itself. Allowed syntax seems to change from system to system. I've set up some commands that were great on one server and that didn't work at all on another.
To create a cron job inside of cPanel, follow these instructions:
1. Log into cPanel.
2. Scroll down the page until you reach the
Advanced section and then click on
Cron Jobs.
3. On the next page, you'll see a warning:
Warning: You need to have a good knowledge of Linux commands before you can use cron jobs effectively. Check your script with your hosting administrator before adding a cron job.
By looking around online, you'll likely find some good instructions for setting up various types of cron jobs. I'm not sure I know any Linux commands and I've been setting them up for 20 years. So just do your homework before trying something like this out.
You'll also see a field where you can enter an email address that will receive a message every time the job runs. I don't usually add any email address, but it's not a bad idea. I used to utilize this feature, but not anymore.
4. Scroll down the page until you see the
Add New Cron Job section. In this section, you'll notice a few different things. The top drop-down that's named
Common Settings will give you some very, well, common settings that people have used pretty much forever. Settings like
Once Per Hour and
Once Per Day. Even if you don't use these common settings, it's not a bad way to learn about how to set up times for your file to be triggered. If you want it to be triggered every day at midnight, then you'd choose the
Once Per Day option and see what cPanel fills in for you. Check it out:
As you can see, all you need to do is fill in the fields to set your time. An asterisk tells the server that you want the cron to run every day. You wouldn't usually use an asterisk for the hour field (maybe you would), but you really wouldn't want to use it for the minute field, unless, of course, you wanted the cron to run every single minute. I guess there are some scripts out there that might require that. Anyway, fill in those time fields.
5. At the bottom of this area, you'll add your cron command. You'll obviously need to know how to write commands, but if it's something simple you need to do, your web host should be able to help. Hosting companies are full of system admins who know this stuff.
6. When finished filling in these fields, press the
Add New Cron Job button. After you do that, you should see the cron you just entered directly below, under the
Current Cron Jobs heading.
Here are some resources for you if you'd like to learn about some common cron jobs that people run as well as how to write cron commands:
https://www.thegeekdiary.com/10-useful-cron-examples-to-schedule-jobs-in-linux/
https://opensource.com/article/17/11/how-use-cron-linux
https://www.computerhope.com/unix/ucrontab.htm
https://www.ubuntupit.com/amazing-linux-crontab-commands-for-the-sysadmins/