301: How to run a cron job

Written By: Brad Markle
Experience Level: Beginner
Articles labeled as Beginner are those that require basic tasks to be completed, such as making simple configuration changes following a brief set of instructions. If you find yourself needing assistance, our Technical Support Department can generally assist.
Print E-mail:
In addition to this article, we also have a video tutorial to show you more on:

You can use cPanel's Cron Job feature to run Unix commands and/or automate the execution of your PHP, Perl, or Python Scripts. To create a Cron Job, you would first log in to your cPanel under "Cron Jobs" then select either "Standard" or "Advanced." You can also specify an email address that the Cron daemon will send the job's results to.

Set up the Crontab

You can do this easily in Standard Mode, but if you are using advanced you'll need to pay attention to time fields:

Specify when the cron job will run. The order is:

[minute] [hour] [day] [month] [weekday] [command]

41 04 * * 1 /my/script -v

This will run every morning at 4:41AM. The * is a wild card, meaning "every day/month, etc" For example; 41 04 * * 1 = every 41 minutes of every 4th hour of ever day of every weekday of month. Weekday is every day of the week including the weekends. Many customers have thought that weekedays are only Monday - Friday, instead of interpreting it as Monday - Sunday.

Specify the command to run the php script

The command will have 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

 The script will need to be called on its direct path as it is located on our server, so it will be something similar to: /home/userna5/public_html/path/to/script, with "userna5" being your username.

perl/cgi scripts should be in your cgi-bin, with permissions of 755 Please read our article on file permissions for more information. 

  • To run a PHP script: php -q /home/usern5/public_html/scripts/testrun.php
  • For Python scripts: python /home/usern5/public_html/path/to/script
  • For Perl/CGI scripts: /home/usern5/public_html/cgi-bin/yourscript.pl

Using the User Agent String

The wget command is disabled on all the shared servers for security purposes. Most scripts that are run via wget can be used with the lynx or curl command. The new mod_security rules that were applied with the latest php updates will prevent lynx and curl from working if a user agent is not set. To set the user agent, you can use the following command:

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

If you need further assistance please feel free to ask a question on our support center website.

 
Rating:
 
Please log in to rate this article.
Like this Article?
Notify Me of Updates!
Please login to subscribe to receive notifications when this article is updated.
Prerequisite Articles
None

Comments

Currently no comments

You must log in before commenting.

Need more Help?

Search
Current Customers
Chat:Click to Chat Now
Call:888-321-HOST (4678)
E-mail:support@InMotionHosting.com
Ticket Submit a Support Ticket
Ask the Community!
Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.
Not a Customer?
Get web hosting from a company that is here to help. Sign up today!

Follow InMotion Hosting!

 4236 Followers. Follow Us!

Continuing Education

Follow this Education Channel to stay up to date on cPanel! (what is this?)
If you're familiar with the traditional setup of college courses, then learning through our Education Channels will be a breeze. We begin with an introductory 101 class, and advance all the way up to 300 level classes. Stay up to date on your favorite topics by becoming a fan on facebook and following us on twitter (links in the right sidebar of the page).
  Followers. Follow Us!

Further Your Education!

Subscribe To Other Education Channels!

Everything Email
Website Design
Premium Website Builder
cPanel
WordPress
Using Web Host Manager
OpenCart
Magento Tutorial

Have a Question?

If you need some help, submit your question to our Community!
We guarantee a response within 60 minutes (8am - 5pm EST, Monday - Friday)

Recent Questions