Cron is a time-based scheduling utility that automates tasks. We like that! Not only does it encourage us to do more with the server, for instance to rotate logs or mechanise backup, cron jobs mean more time down the pub. Here’s how to set it up.
Maybe you’ve used cron jobs in a shared hosting past life? To simplify this guide we’ll compare using cron in a control panel like cPanel alongside creating the equivalent tasks using the command line. Remember, the panel option is simply a shiny GUI way to set up the exact same server-side cron process.
Setup Unmanaged VPS: The Ubuntu-Nginx Guide
Take your virtual private server from zero to hero
.. from blank box to cute-as server ..
with this easy-to-follow copy/paste guide.
22+ parts with video, here’s the index.
Set up Cron Jobs from cPanel
cPanel or not, the procedure for setting up a cron job in a panel is broadly the same.
Click on the icon for something like Cron Jobs in your CP and you arrive at a page where you can Add New Cron Job, edit existing jobs and receive an email when jobs are done.
The scheduler itself is pretty self-explanatory. In cPanel there’s a Common Settings drop-down with scheduling presets so you could be lazy and use one of those.
Let’s say you want a weekly disk usage report echoed to a file. Here’s the ‘nix command.
du -h --max-depth=1 ~ > tmp/du
And in the piccy at the top of the page you can see that command applied to cPanel’s cron scheduler, together with a weekly preset that can be set uniquely, else via one of those Common Settings defaults.
Nice and simple. Not exactly fast, what with all the page loads, but brain-dead easy. Using the terminal to achieve the same thing, though, is hardly rocket science and, understood, saves time.
Set up Cron Jobs from the Terminal
Control panel or not, this is quicker and easier. For one thing, invariably you need to create some simple script or other that you want cron to run so, hey, you may as well create that and add the cron job at the same time. Edit the crontab file, where cron jobs are ordered.
crontab -e
If this is the first cron job you’re running the crontab file will be created. If you already added the above cron job example you’d see it listed in cron’s file.

To break down cron’s syntax that we provide to set up a task, we have this.
* * * * * doSomething
It’s dead simple to understand. It’s merely five time options along with some task.
minute(s) hour(s) day(s) month(s) weekday(s) <em>command(s)</em>
So no big deal there, then. Say you want a daily whatever. Do this.
15 22 * * * whatever
Registered in the crontab file, that sets whatever to clock in each day at 22:15 hours.
Security Tip 1: Check for Con Crons
Given the chance, hackers will use cron for dastardly deeds. We need to check for unusual jobs in the crontab file.
If there are any cron jobs you didn’t set up, remove them or #comment them out while researching what they do.
Security Tip 2: Restricting Cron Access
Clearly cron is a pretty powerful tool. A related task scheduling tool is at.
If you have a shared or multi-user environment you should restrict use of the at and cron tools to the root superuser and, maybe, to your human administrators.
To do that create two allow files, in this case using the nano text editor.
sudo nano /etc/cron.allow sudo nano /etc/at.allow

Within each, add the users to allow, one user per line. You should add root to each.
You must also create the converse deny files.
sudo nano /etc/cron.deny sudo nano /etc/at.deny
They can be blank. However, don’t create blank deny files unless you’ve populated allow files because that gives global access.
Cron for Windows
Some of you less fortunate types, running Windoze locally, may be wondering how to use cron to automate various stuff on the local box. Well, sorry but you can’t. There’s always the Windows Task Scheduler which, admittedly, is pretty fair play. There’s also cron’s dozy cuzzie, cronw, so check that out.
- cronw – http://cronw.sourceforge.net
Cron-tastic
So there’s a brief heads-up into this top administrative tool. You may be wondering how to use it to do something more useful than checking your disk space. Fair point …
Securing Off-Server Backups using Cron Jobs
Aah. Nice. In the next few days we’ll have a spanky new tutorial about how properly to backup a database so that it’s not sitting around your server in a text (.sql) file, nor being emailed in plain text, but correctly is being sent to you scrambled with the server having no trace of the relatively easily hackable data dump. Definitely check that out. I’ll link it here. Ciao for now.
Setup Unmanaged VPS: The Ubuntu-Nginx Guide
Take your virtual private server from zero to hero
with this easy-to-follow copy/paste guide.
“My local PC runs Windows” Show me for Linux/Mac
“My local machine is Linux/Mac” Show me for Windows
22+ parts with video, here’s the index ..
-
Setup Unmanaged VPS: The Ubuntu-Nginx Guide
Introducing vpsBible’s how-to guide for setting up a super-charged unmanaged VPS featuring Ubuntu and Nginx.
-
VPS (Virtual Private Server) vs Shared vs Dedicated
Before getting stuck in, let’s compare the web host types in detail and weigh up the differences between managed & unmanaged VPS.
-
Set Up a VPS Linux Distribution
Opening a VPS hosting account, we’ll choose, configure & launch a Linux server ‘distribution’.
-
Set Up Command Line Interface (CLI) using PuTTY
Now we’ve got a server to play with, we’ll connect to it, using the ’ssh’ protocol for a super-secure link.
-
Create a Linux User & Set Permissions
Initially you’ve logged into your remote Linux machine as ‘root’. We’ll add you as a user now, with root or SuperUser permissions.
-
Encrypt Data with OpenSSH & Auto-Login with PuTTY
Now we can use ‘authentication keys’ to shore up our connection while simplifying login to an automated, password-free yet secure process.
-
Harden the Secure Shell (SSH) & Create a Firewall
The final security step: galvanizing the OpenSSH protocol and setting up an ‘iptables’ firewall. Now the server is rock ruddy solid.
-
Edit bashrc for User-Friendly Linux, plus System Updates
We use the terminal a whole lot so let’s cut ourselves a break and create some command shortcuts, then update the server.
-
Add a Domain Zone to Your VPS
To make your server aware of yourDomain.com you’ll need a few ‘DNS’ records. Damn this is simple I’m practically asleep!
-
Prepare Linux Server for Email with Postfix
In order to send and receive email from our web applications we’ll install some software and tweak the ‘RDNS’ record.
-
Install PHP5 & MySQL – The One-Stop FastCGI Index Page
Add PHP5 & MySQL, but which FastCGI method is best? Here’s the benchmarking, 4 ways to install/compile, add caching modules & more.
-
Nginx (better than Apache) Web Server
Let’s install this supersonic web server, tweaking its file structure & adding default configuration files.
-
Setup FileZilla for Secure FTP (SFTP)
There’s FTP, and then there’s ‘Secure FTP’. We’ll set up FileZilla using SFTP – and those authentication keys – for secure file transfers.
-
Serve Multiple Sites & Blogs with Virtual Hosts
We want a website folder structure, some permissions, some site-specific configuration files and, hey, we’ll hook up ‘FastCGI’.
-
Adding Sub-Domains with Nginx
Need a sub-domain? If you do, here’s how to add subDomain.yourSite.com with an ‘A record’ and a configuration file.
-
Integrate A CMS Like WordPress, WP MU, Drupal etc
For those of you wanting to use a specific content framework, such as a CMS, blogging or forum software, pop in here and we’ll sort that out.
-
Google Apps for Domain-Specific Email
GA’s free Standard Edition for catchall webmail – POP-ping or IMAP-ped to your desktop client – saves precious server resources for your webs.
-
Moving Day! How to Move Your Blog or Site
Nearly there. Here’s the web site or blog migration guide, relocating to your VPS with minimal or no downtime.
Manage Unmanaged VPS: Ubuntu-Nginx Administration
Already set it up? We’d best maintain it then.




















Got a Question? Want to Comment?
This site has no comments system. We've got a better system!
Please use the link at the top of the post and goto this topic's forum thread:-
For those posts ported from Guvnr.com (pre-Feb/2010), archive comments remain.
Handy info from these comments is in the process of being ported to the forum and attributed to the original author.
If you think this idea sucks, let me know.
Thank you.