Crontab Examples

A crontab (cron tables) is a configuration file that specifies shell commands to run periodically on a given schedule. The commands in a crontab file (also known as a “cron job”) are executed by the cron daemon, a built-in Linux utility that runs processes on your system at a scheduled time.

Each line in a crontab file represents a separate cron job and follows a specific format, consisting of six fields separated by spaces:

* * * * * command

The fields represent the following:

  1. Minute (0-59)
  2. Hour (0-23)
  3. Day of the month (1-31)
  4. Month (1-12)
  5. Day of the week (0-6, with 0 being Sunday)
  6. The command to be run

The asterisks in the first five fields indicate that the command should be run every minute, every hour, every day of the month, every month, and every day of the week, respectively.

To edit your crontab file, you can use the crontab -e command, which will open the file in a text editor. When you are finished editing the file, save and exit the editor to activate the changes.

Crontab Examples

To run a command at 4:00am every day, the entry in the crontab file would be:

  
0 4 * * * command
  

To run a command every Monday at 6:00am, the entry would be:

  
0 6 * * 1 command
  

To run a command every 15 minutes using a crontab, you can use the following entry:

  
*/15 * * * * command
  

To run a command every 4 hours using a crontab, you can use the following entry:

  
0 */4 * * * command
  

To run a command at 3:15am every day using a crontab, you can use the following entry:

  
15 3 * * * command
  

Category : Knowledge Base