Wednesday, February 22, 2023

What is the syntax for setting cron to run every 2 minutes?

If you're familiar with Linux system administration, you know cron – the automatic scheduler for tasks – is a powerful and convenient tool. And if you've used cron before, you know that specifying the timing for cronjobs in the /etc/crontab file can sometimes require some figuring out. In this article, we'll provide a quick guide to setting up a cron to run every two minutes.

The syntax for setting a cron job to run every two minutes consists of 6 components: minute, hour, day of month (DOM), month, day of week (DOW) and full path to the command. For a cron job running every two minutes, all the components need to be set in order:

• Minute: 0-59/2 (0-59 followed by "/2")

• Hour: *

• DOM: *

• Month: *

• DOW: *

• The full path to your command

Hence, if everything is set correctly in your crontab then your command should run every two minutes. Here's an example with all possible variables in place:

0-59/2 * * * * /path/to/command

This specifies that your command should execute at 15 seconds past the minute (0 + 15 = 15 seconds), 2 minutes past the hour (0 + 2 = 2 minutes), at any day of month (* = any day), in any month (* = any month), on any day of week (* = any weekday). If all other variables are left unchanged and you set "*/2" under Minute section it will run twice per minute. To add multiple commands within a two-minute interval just add them after each other with identical timeseting as we did above. Do not forget about the full path to each command!

See more about cron every 2 minutes

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.