Cron Job – What Is It and How to Run It (GUIDE)

Cron Job is a linux service that is tasked with doing a specific assignment in a given timeframe which the user has configured. It gives us the convenience to complete certain commands or scripts in a given time interval or a moment automatically.

Such commands can be triggered every day at a schedule, every week or even each hour. Via the cron job service, we can start different types of scripts, like:

  • PHP
  • BASH
  • PERL

How to Add New Cron Job

Adding a Cron Job is not as dificult as it seems. It can be done remotely with any cPanel of your server. But first, let us talk through why you need a cron job.

Lets say that you want to set up once in exactly 03:04 A.M. time for a task to run a PHP script, which would eventually extract from your database info on all of the registered users on your site and generate a report. Here are the steps to do this:


Step 1: Get to your cPanel and click Cron Jobs. It should be located somwhere in the “Advanced” or “Settings” section of your cPanel. It really comes down to what version of cPanel you are using and what type of administrative panel you are using.

Step 2:Write the script and place it on your public_html folder. Depending on your server you can place it in any given folder as long as the directory is on the server.

Step 3:When you click on “Cron Jobs”, you might see a screen like the one below. Set up the Minute, Hour, Day, Month, Weekday and finally write where your script is actually located along with the “php5x” command before the location, like shown below:

Step 4:After you have filled in all the information, click on “Add New Cron Job” button. The job could be seen in the Current Cron Jobs Menu:

How to Create a Cron Job Using Linux Server Commands

Cron Jobs can also be triggered via CLI (comman line interface) of your server in case it is linux based. For the Ubuntu servers, to see the list of cron jobs created you can type in:

→ $crontab –l

And to edit your current cron jobs, you can type in:

→ $crontab -e

If this is the very first time you are asked to choose a cronjobs, you will see the following command answer:

→ no crontab for sk – using an empty one

→ Select an editor. To change later, run ‘select-editor’.
1. /bin/nano <---- easiest 2. /usr/bin/vim.basic 3. /usr/bin/vim.tiny 4. /bin/ed Choose 1-4 [1]:

You can type in the type of cron job you want to trigger and activate it.

If you want to edit the cron job list of a different user, you can type in the following:

→ $crontab -u {the username} -e

If you want to trigger the cron job to run on the 6th, then 15th and then 0 minute for 1 hour, you can edit it like this:

→ 0,5,10 and the command to be executed on your server

You can also use “@” with the time interval you want a cron job to run, like for example:

→@monthly – once a month
@midnight – once a day on 00:00 server time
@reboot – on server reboot

If you want to run the command this way, you can use simply:

→@midnight and the command to be executed each mindight

If you want to fully erase off your created cron jobs, you can use:

→ $crontab –r

What Is Cron Job – Conclusion

Basically, a cron job is like task scheduler, but for your server. It can be set to trigger different scripts or commands based on a schedule and you can use it every time when you requre a task to be completed automatically and most importantly at times when you won’t have the time to manually enter a command yourself. Not only this, but some Cron Jobs are even set to run sophisticated scripts that give site owners crucial information and statistics for their sites. So they can be extremely useful as long as you can manage them correctly.
Here are some free Cron Jobs, kindly provided by the site Cronless, that give your server the abilities to:

  • Run backups of your database automatically.
  • Perform automatic updates inside a game, forum or site.
  • Schedule auto tweets in the future.
  • Generate invoices automatically for a period of time.
  • Do a cleanup or automated site maintenance.
  • Update your RSS feed.

The site has 5 free Cron Jobs in its 0$ a month plan and this can help simplify the process for you.

There are also very useful Cron Job Generators, like Cron Tab Generator that can help a lot by being user friendly and generating commands for you in your server and all you have to do is click what you prefer running.

Leave a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.