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 […]
  • 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 […]
  • Move MySQL tmp directoryMove MySQL tmp directory You’ll eventually run into a client who has a crashed table in their database – this table will be pretty large – maybe even larger than the system’s default temporary directory (usually […]
  • Rescued my little Acer C7 ChromebookRescued my little Acer C7 Chromebook After installing chrubuntu on my c7, I decided to put it back to factory and give crouton a try so that I could run both chrome and crouton at the same time.  I created the restore usb […]
  • Import MySQL database from command lineImport MySQL database from command line You’ll need to import a database via command line from time to time – I’ll normally opt for this anyway. After seeing how easy it is, you’ll probably end up using the command line instead […]

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 to Sal Cancel 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=""> 

*