Save Time: How To Set Up A Cron Job
Print Article
Save Time: How To Set Up A Cron Job
Everyone knows there are tasks to administer to our computers and servers that we don’t do as often as we should. It takes time to back up or or clean up files or perform other repetitive, administrative-type tasks, so we avoid them doing them regularly; meanwhile, we’re one system crash away from losing everything. Luckily, your Linux system has a built-in tool to help you take care of such time-intensive tasks. It’s called a “cron job,” and, if used properly, it can to do the things that keep your systems flowing and your site running smoothly.
What Is A Cron Job, Anyway?
A cron job is a program that allows you to execute commands or scripts on a Linux-based system (usually a server) at a specified time and date. So exactly what kind of tasks can a cron job accomplish for you, then?
- Backing up not only your MySQL databases, but also your website’s content. It’s recommended that you do these jobs once a day, at some off-peak hour like 2 A.M.
- Generating sitemaps on a monthly basis, thereby increasing your site’s SEO and chances of being found and highly-ranked by search engine’s spiders. Again, we recommend doing this regularly (monthly) and at off-peak hours.
- Deleting unnecessary files, such as old backups. This is a job best reserved for advanced users, though, since you don’t want to delete needed files. Tread with care on jobs like these.
OK, so now that we know the theory – what a cron job is and what you can use it for – let’s look at how it works. If a cron job is a script that runs at a given time and performs a certain task, then the script you use to execute the task needs to contain these elements. Each script must contain six components: the minute, the hour, the day (date), the month, the day of the week, and the command line to execute.Use the asterisks for wildcards (that is, the places you don’t have values for), and everything else tells your system when, where, and what. Remember, though – you have to write the script yourself. The cron job just pushes the button that tells the job when to start.
cPanel’s Cron Job Interface

Having a web host that offers cPanel on your sites makes this process quite a bit easier. Go to the cron jobs tab on cPanel, use the tables to select the time, day, and frequency, insert the code for the task, and you’re done. By offering this option, cPanel removes a lot of the guess work about scheduling cron jobs, making it a simple visual interface – yet another reason to love cPanel. Moreover, you can use the interface to simultaneously schedule multiple cron jobs – just get your scripts in order and let it do its job.
A Word Of Caution
One tip – make sure to schedule cron jobs during off-peak hours; for example, during the middle of the night when your server isn’t doing its daily work. Cron jobs can end up being a drag on a server if not properly scheduled. Also, make sure your scripts work properly, or else a cron job can run unnecessarily, too often, or get caught in a loop where it runs nonstop. That’s a drag on your server’s resources as well.
That said, a cron job is a great tool if you know what to use it for and how to get it done. So study up, set the job, and relax while a cron job takes some of the repetitiveness out of your computing life.
There are many online resources to help you figure out how to write executable scripts for cron jobs, including examples of the cron jobs mentioned above. Two good resources can be found at APLawrence.com and NixCraft.
