All posts tagged linux

Linux crontab – run a command every minute

To run a Unix/Linux crontab command every minute, use this syntax:

I created that entry when I was having a problem with Apache, and needed to run a test every minute of every day to see that it was running properly. All those “*” symbols are what make this command run every minute. Specifically, those first five fields have the following meanings:

I’m assuming some previous knowledge of the crontab syntax in this tutorial, so I won’t discuss this much, but what I’m trying to show here is that in the first field you specify the “Minute” value, in the second field you specify the “Hour”, followed by Day Of Month, then Month, and finally Day Of Week. We’ll see more examples as we go along.

Run a crontab command every hour

To run a Linux/Unix crontab every hour of every day, you use a very similar syntax. Here’s a crontab entry I use to hit the Drupal cron.phppage five minutes after every hour:

Run a crontab entry every day

Here’s a crontab example that shows how to run a command from the cron daemon once every day. In this command I run my backup scripts at 4:30 a.m. every day:

Run a crontab entry every 5 minutes

There are a couple of ways to run a crontab entry every five minutes. First, here’s the brute force way:

That command works just fine, and there’s nothing technically wrong with it. It’s just that the crontab syntax offers a shortcut for this situation. The crontab step syntax lets you use a crontab entry in the following format to run a Unix or Linux command every five minutes:

That’s a nice convenience feature for situations like this. Here’s a nice blurb about the step command syntax from the crontab man page:

Unix and Linux “crontab every” summary

I hope that’s enough examples to help you run your own crontab commands every minute, every 5 minutes, or every day, or every five minutes, etc.