How to Set Up Cron Jobs for Optimal System Performance

by Brian Flores December 13th, 2011 

Although many website functions run automatically using a database, there are some tasks that must be performed manually. If you are using a Unix-like system, you can use a cron job to schedule tasks. A cron job lets you schedule jobs, shell scripts and commands to run at set times. Many web designers use them for system maintenance or other admin tasks. Using a cron job lets you save time by scheduling mundane tasks, and this also helps ensure you do not forget to do these tasks.

You may have the best intentions, but boring, time-consuming tasks are often put off or forgotten. You may put off backing up your website or performing scheduled maintenance, but these are important tasks to keep your website running smoothly. Without a backup, if your website crashes, you can lose months, or even years, of data.

Cron jobs are mainly used for administration and system maintenance, but they can be used for smaller tasks having to do with the Internet and email. Since they can be used for so many difference functions, they are versatile and save you time and money.

Why Are Cron Jobs Important

Cron jobs are scripts that run at a specific time to perform a specific function. They can be used to run important tasks that are essential to run a website. They can be used to create daily backups and create sitemaps that include new pages.

When creating the script for a cron job, these things must be present:

cronjob

  • Command line
  • Date
  • Day of the week
  • Hour
  • Minute

Entering these values creates a completely automated process to perform various functions. Be careful to write the script correctly, or the cron job will not work as it is supposed to.

Cron jobs can be used to help your website run at peak performance. It is recommended that you schedule website backups for all databases and content daily using a cron job. Other useful applications include generating sitemaps monthly for search engine optimization (SEO) purposes and deleting old files to save space. Leaving old backups and files on your server can cause it to run slower and visitors will experience slow loading times. Using a cron job to delete files should only be done by experienced users, as this can be disastrous if not written correctly.

When To Schedule Jobs

Schedule jobs to run at off-peak times, such as the middle of the night for your largest geographic visitors. Cron jobs can slow down your website loading times, and visitors will soon become frustrated and leave. Running jobs too often can also slow down the server. Ensure that all scripts are written correctly to reduce the length of time they run.

Your Cpanel And Cron Jobs

372926381_a4cadcd99f_o

A cron job is easy to set up in your website's cPanel. Go to your cPanel and look for a link titled "Cron Manager." Select the time, date and frequency for the task, then enter a code for that task. This easy interface lets you create multiple jobs under the cPanel. If you can not easily find the link to set up a cron job, contact your web host's support to find out the availability and where they are.

How To Write A Cron Job

You can find help to create your own cron jobs on the Internet. Some websites will give you examples and advice to create your own. Try NixCraft and APLawrence.com for more information.

Writing these scripts can be time consuming and tedious, but they save time and resources later. Using cron jobs properly ensures that your website will run at top performance with less work from you.

Brian Flores

Brian Flores is a SEO and blogger for InMotion Hosting, a provider of virtual private servers in the United States. You can follow him on Twitter @BrianAFlores.

Brian Alex Flores - SEO Specialist

You May Also Like

3 Responses to “How to Set Up Cron Jobs for Optimal System Performance”

  1. Margurite says:

    You can start by promoting your blog on blog directories, and promoting your individual articles on social bookmarking websites, as well as using traffic generators to get your blog noticed. It is very, very hard to create a winning blog, since there are so many on the internet these days, but you can seperate your blog from the rest of the pack by getting followers to you blog on specific information that might interest them.

  2. barak says:

    Hi, do u know about an equivalent plugin for wordpress?
    losing my website data sounds not good.
    after i rade your post cron jobs doesnt sounds frightning any more. its a doable thing to do for everyone.

  3. Ryan Cowles says:

    Great article! Cron jobs were something that I didn't know about at the early stages of my web development career. Necessity lead me to learning how they work, and how to write them, and word can't describe how useful they have been. One of the biggest tasks I have found them useful for is server and database backups.