Understanding cron job times

Rob —  July 24, 2014 — 2 Comments

Often, you’ll want to use cron to schedule daily, weekly, hourly (etc…) tasks on your linux system(s). cPanel has a little GUI for it, but since I don’t trust GUIs very often, I like just doing it the ‘old fashioned’ way. This little guide will hopefully help you to figure out cron once and for all.

Ok, so cron is what is used on your Linux system to schedule repeating events. It’s used to rotate logs, run clean-up scripts, and anything else you can think of that you’d want to schedule.

To view your crontab (view the current cron jobs for your user) simply type in:

To edit your crontab (edit the current cron jobs for your user) type in:

If you are root and you want to edit another user’s crontab, you can specify them like:

A typical cron entry looks like this:

Let’s break this down. There are 5 fields before the actual command:
From the man page:

For ‘month’ or ‘day of week’, you can use the first 3 letters – case doesn’t matter.. ie: sun, mon, tues… or jan, feb, mar.. etc..

Then, you’ll see the command – in this case, it’s a mysql backup script.

Let’s run through a couple examples:

Run a command once/week scheduled Saturday morning at 6am:

or

Now, let’s only run it on Saturdays in August:

How about every 5 minutes all the time:

How about every other day at 10am!

Hopefully, this will help clear up any confusion you’ve had with cron! Let us know below!

Related posts from Linux Brigade!

  • Manually run ClamAV on cPanel and check every userManually run ClamAV on cPanel and check every user If you’re running WHM/cpanel and want to run a scan on every user manually, perhaps when first installing ClamAV, you’ll want to run this command which is endorsed by cPanel […]
  • Install nrpe on XenServerInstall nrpe on XenServer If you are using nagios in your hosting environment and need to install nrpe on your XenServer servers, here’s a good way to do it.
    I’m using XenServer 6.1 (latest version).

    First, […]

  • How to use GNU Screen in LinuxHow to use GNU Screen in Linux Screen is billed as a “full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells)” (from the man page). Linux admins use […]
  • Check, repair, optimize all databases with one commandCheck, repair, optimize all databases with one command My server had some tables marked as ‘crashed’ in one of the databases.. the server had recently gone down pretty harshly so I wanted to go through and check, repair and optimize all of the […]
  • Valve’s Steambox will help Linux gamingValve’s Steambox will help Linux gaming If you’re a gamer, then you’ve heard of the steambox. This is Valve’s answer to the xbox, ouya, etc.. offering gaming in your living room.

    They’ll be announcing something today at 10am […]

2 responses to Understanding cron job times

  1. For some of the users, they don’t have cron on server, or the server limits the cron use. In those cases, EasyCron is an option. To those who don’t know how to use crontab, EasyCron is a great alternative 🙂

Trackbacks and Pingbacks:

  1. Delete cPanel account error_log files | Linux BrigadeDelete cPanel account error_log files - July 24, 2014

    […] suggest that you schedule a cron job to clear them out weekly.. like, let’s clear them out every friday […]

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url=""> 

*