IBM Support

How to run a cron job every 5 minutes

Question & Answer


Question

How to run a cron job every 5 minutes

Answer

Description

A cron job is a task that is scheduled to run periodically on Unix-like systems. This is useful if you have a script that needs to be run every so often, such as a script to clean up a directory at the end of each day. The following instructions demonstrate how to set a cron job to execute a script every five minutes.

Instructions

Use the command crontab -e to edit the crontab. This uses the editor specified in the environment variable$EDITOR, and if the variable is empty, this defaults to vi(1) or vim(1)

The format of a crontab is 6 columns, space (or tab) separated. The first 5 columns detail the time when to run a command, which is specified in the last column. The last column" makes up all the remaining characters inclusive of spaces. Here is an example:

5 * * * * /home/aspera/my_script.sh

What the above shows per column:

  1. Minute to run on a value of 0-59: 5 means on the 5th minute of the hour
  2. The Hour a value of 0-23: * means every hour
  3. Day of the Month 1-31: * means every day of the month
  4. The Month 1-12: * means every month
  5. Day of the Week 0-7 (0 and 7 are both Sunday): * means every day
  6. The Command: In this case a command at/home/aspera/my_script.sh

With older crontabs like the one on legacy Solaris this is mostly all that can be done. One variation is to use comma separated lists. Modern crontabs can use string names for days and wildcards with increments. So to create an entry that runsmy_script.sh every 5 minutes would be as follows on Linux:

*/5 * * * * /home/aspera/my_script.sh

The */5 notation in the first column means "every 5 minutes". To make this every 10 minutes */10 is used. To do the same 5 minute interval on a Solaris system try the following:

0510152025303540455055 * * * * /home/aspera/my_script.sh

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SS8NDZ","label":"IBM Aspera"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
08 December 2018

UID

ibm10746351