Business Management | Editors Column | Hosting Customers | Interviews & PR | Marketing/Advertising | Online Marketing/SEO | Web Hosting | Web Hosting Reviews

Web Hosting Reviews and Tutorials

Cheap Web Hosting - iPage - Click here

How to write a cron job?

by WHRKIT on March 6, 2005

How to write a cron job?

The crontab command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. It reads a series of commands from standard input and collects them into a file known also known as a “crontab” which is later read and whose instructions are carried out. Generally, crontab uses a daemon, crond, which runs constantly in the background and checks once a minute to see if any of the scheduled jobs need to be executed. If so, it executes them. These jobs are generally referred to as cron jobs.

Each crontab or cron job shares the same format:

minute hour day month weekday command

Whether if you create or change a cron job within cPanel or directly in the file, each crontab will use the above format, and each field can contain:

* A Star, = everything

* A single number

* Two numbers separated by a dash, = a range.

* A comma-separated series of numbers or ranges,= any listed value.

For example:

40 10 * * 1-5 means 10:40am, Monday through Friday

Or..

32 13 * * 0-4,6 means every day except Fridays at 1:32 p.m

One of the most common uses for cronjobs for a user will be to execute a PHP file on a period schedule. Example:

php -q /home/username/public_html/path/to/your/script > /dev/null

lynx -dump http://example.com/file.php <http://example.com/file.php> > /dev/null

These two commands will execute the php script. Note that > /dev/null is on the end of both of these commands. This will silence any errors or output that might be created by the above commands. The cPanel control panel allows for an email address to be entered. If you would like to receive the output from the commands, you enter your email address. However – this last step is optional.

Related posts:

  1. Automating Tasks in Linux using Cron
  2. CHMOD – Understanding File Permissions on a Unix-Based Server
  3. CPanel: Backup and Restore a Domain Account via SSH
  4. Apache Webserver – A quick tutorial for new Admins
  5. How to rotate your Apache Log Files?
  6. How to write good ads for PPC advertising?

Leave a Comment

Previous post:

Next post: