A Web.com Partner
Sign Up / Log In
Online Support Web Hosting

How to Set up a Cron Job

Cron is one of the useful utilities that you will find in Unix operating system. It allows you to schedule commands at a specific time. These scheduled commands are known as Cron Jobs. In this article, you’ll learn how to create a cron job and understanding the common commands to run a cron job via your Hosting Manager.

But first we’ll help you better understand the commands ro run a cron job.

What Are the Commands to Run a Cron Job

The command contains two parts:

[program to execute (perl/pyth./php)] [switches] [script]

The program to run will specify the type of script you are running and will either be:

  • PHP
  • Python
  • Perl/CGI Scripts (should be in cgi-bin with permission 755)

The script will need to be set on the direct path where it is located on our server, for example: /home/username/public_html/path/to/script, with username being your username.

Run a PHP script:

php -q /home/username/public_html/scripts/testrun.php

Run a Python script:

python /home/username/public_html/path/to/script

Run a Perl/CGI scripts:

/home/username/public_html/cgi-bin/yourscript.pl

Understanding the User Agent String


We have disabled the wget command for security purposes. You can run most scripts that require wget with the lynx or curl command. The latest update of mod_security and php updates will prevent lynx and curl from working if a user agent is not set.

Below is the command to set the user agent:

curl --user-agent YOUR_STRING (URL) 
lynx -dump -useragent=YOUR_STRING (URL)

Now that we’ve established few of the commands. Let’s learn how to create a cron job. Continue reading this article to learn how.

How to Create a Cron Job

Follow the steps below to create a cron job.

Step 1. Access your Hosting Manager.
Step 2. Scroll down to the Advanced tab, then click on the Cron Jobs option.
cron job option cPanel
Step 3. Under Add New Cron Job, select Common Settings from the drop-down list.
Step 4. Set the following details to schedule your command:
Minute Enter a number from 0-59.
Hour Enter a number from 0-23.
Day Enter a number from 1-31.
Month Enter a number from 1-12 or the first three letters of the month, example, Jan
Weekday Enter a number from 0-7 or the first three letters of the weekday, example, Mon..
add new cron job
Step 5. Under Command, specify the command to run then click Add New Cron Job button.

Congratulations! You just successfully created and run a cron job. If you need any further assistance or if you have any questions in setting up a cron job, please let us know. We’d love to help!

Was this helpful? Yes No 76% of people found this helpful.
{"message":""}