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 […]
  • Run the same command on many Linux servers at onceRun the same command on many Linux servers at once Ever have to check a list of Linux servers for various things like what version of CentOS they’re running, maybe how long each has been running to get an uptime report? You can – and it’s […]
  • Bash ShellShock bug – Find out if you’ve been “tested”Bash ShellShock bug – Find out if you’ve been “tested” We’ve seen the articles about how to find out if you’re vulnerable to the bash shellshock bug, we’ve also seen the articles on how to patch your system.  What I’ll show you is how to find […]
  • CentOS 7 / RHEL 7 systemd commandsCentOS 7 / RHEL 7 systemd commands By now, if you’ve played around with CentOS 7 (or RHEL 7), you’ve heard that there are now systemd commands you can start using to start, restart and stop various services. They still […]
  • Try a DigitalOcean VPS free for a month (or two)Try a DigitalOcean VPS free for a month (or two) Have you been meaning to try out an SSD Linux server on Digital Ocean but keep putting it off? LinuxBrigade.com is currently being hosted on a DigitalOcean server and now you can get a […]

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=""> 

*