We value you as a customer and your website(s), and as a courtesy just for being our customer. Your website(s) are automatically backed up, FREE. Our Servers back-up websites Daily each day will over wright the previous day. We also suggest you do your own backup and every time there is a change backup and download it to your local computer ( learn how to backup here ). If you don't already, we suggest you check your website at least once every day, (this way if you ever have a problem we can restore the site for you). posted 10-01-2023

HOWTO: Basic crontab usage Print

  • 4

Hello,

In this guide, we will go over how to add a cronjob using the cPanel crontab
section. The crontab is a useful tool if you have a single command to run many times
over and over, or only at certain parts of the day. Want to send yourself an email
every day at 2:45AM? Cronjobs can help you out. Need phpList to automate its list
processing? Cronjobs have you covered.

A CRONJOB is a task that is run by the CRONTAB. The CRONTAB is basically your list
of cronjobs and their commands.

So, how do we use cronjobs?

cPanel has a built in wizard that allows you to create new cronjobs and edit your
crontab from your browser. To access this, first login to your cPanel and click on
the "Cron Jobs" icon in the Advanced tools section. Next, click on "Advanced (unix
Style)".

This section may appear confusing, but it is actually quite easy to deal with once
you understand how it operates.

first things first, enter a spare email account into the email address field. This
is where the crontab will send an email with the output of the command that is run.
Its advisable NOT to use your regular email account as you will get an email every
time a cronjob is run.

The next step is the confusing part, but hopefully looking at this diagram and some
examples should help you out.


# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7)OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed




Basically, this dictates when the cron should be run. The minute column on the far
left dictates what minute of the hour this should be run on. For example, if you put
15 into the first column, It will run 15 minutes past the hour. A * indicates EVERY
possible number for that column. It is not advisable to use * in the minute column
as the command would be run EVERY minute.

The same rules apply to every column. If you would like to have the script run every
5 minutes, use */5 in the first column, if you want it to run every 10 minutes, use
*/10, and so on.

This rule applies to all of the columns. If you want to have the script run every 5
hours instead of every 5 minutes, place */5 into the second, hourly, column. You
can use this in any column.

Some further examples of a cronjob that processes the phpList queue:

(please note that this is only an example cronjob and may or may not work for your
particular install of phpList)




* * * * * /usr/bin/php /home/username/lists/phplist_cron.php

This will process the phpList queue every minute of every hour of every day of every
month.




5 * * * * /usr/bin/php /home/username/lists/phplist_cron.php

This will process the phpList queue every once per hour on the fifth minute of the
hour. (1:05, 2:05, etc...)




59 11 * * 1-5 /usr/bin/php /home/username/lists/phplist_cron.php

This specific cronjob will process the phpList queue at 11:59AM on Monday, Tuesday,
Wednesday, Thursday, and Friday.




59 11 * * 1,2,3,4,5 /usr/bin/php /home/username/lists/phplist_cron.php

This cronjob is identical in functionality to the previous one. It shows the
different ways you can enter in multiple values.




*/15 9-17 * * * /usr/bin/php /home/username/lists/phplist_cron.php

This cronjob will process the phpList queue every fifteen minutes between the 9th
and 17th hour of the day.




With this in mind, you should be able to write a cronjob to work for any specific
reoccurrence you desire. The command that you need to run itself goes in the right
field. Let's take our phpList queue process script for example.

/usr/bin/php /home/username/lists/phplist_cron.php

This first part, /bin/usr/php, specifies that the cronjob will be processing a PHP
script. The second portion of it is the location of the script that is being run,
and any variables (such as login details) that need to be set for the script to
function properly.


Whatever this script outputs when it is executed will be sent to your email every
time the cronjob is run. If you do not want the output to be sent to you, either
change the email address to /dev/null or put this at the very end of the command you
are running: '>/dev/null'

This will prevent the crontab from sending you the output if you do not require it.


Was this answer helpful?

« Back