Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Run Cron Jobs Every 5, 10 or 15 Minutes - DesignLinux

designlinux 0 Comments

A cron job is a task that is executed at specified intervals. The tasks can be scheduled to run by a minute, hour, day of the month, month, day of the week, or any combination of these.

Cron jobs are generally used to automate system maintenance or administration, such as backing up databases or data, updating the system with the latest security patches, checking the disk space usage , sending emails, and so on.

Running cron job every 5, 10, or 15 minutes are some of the most commonly used cron schedules.

Crontab Syntax and Operators #

Crontab (cron table) is a text file that defines the schedule of cron jobs. Crontab files can be created, viewed , modified, and removed with the crontab command.

Each line in the user crontab file contains six fields separated by a space followed by the command to be run:

* * * * * command(s)
^ ^ ^ ^ ^
| | | | |     allowed values
| | | | |     -------
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

The first five fields (time and date) also accepts the following operators:

  • * – The asterisk operator means all allowed values. If you have the asterisk symbol in the Minute field, it means the task will be performed each minute.
  • - – The hyphen operator allows you to specify a range of values. If you set 1-5 in the Day of the week field, the task will run every weekday (From Monday to Friday). The range is inclusive, which means that the first and last values are included in the range.
  • , – The comma operator allows you to define a list of values for repetition. For example, if you have 1,3,5 in the Hour field, the task will run at 1 am, 3 am and 5 am. The list can contain single values and ranges, 1-5,7,8,10-15
  • / – The slash operator allows you to specify step values that can be used in conjunction with ranges. For example, if you have 1-10/2 in the Minutes field, it means the action will be performed every two minutes in range 1-10, same as specifying 1,3,5,7,9. Instead of a range of values, you can also use the asterisk operator. To specify a job to be run every 20 minutes, you can use “*/20”.

The syntax of system-wide crontab files is slightly different than user crontabs. It contains an additional mandatory user field that specifies which user will run the cron job.

* * * * * <username> command(s)

To edit the crontab file, or create one if it doesn’t exist, use the crontab -e command.

Run a Cron Job Every 5 Minutes #

There are two ways to run a cron job every five minutes.

The first option is to use the comma operator a create a list of minutes:

0,5,10,15,20,25,30,35,40,45,50,55  * * * * command

The line above is syntactically correct and it will work just fine. However, typing the whole list can be tedious and prone to errors.

The second option to specify a job to be run every 5 minutes hours is to use the step operator:

*/5  * * * * command

*/5 means create a list of all minutes and run the job for every fifth value from the list.

Run a Cron Job Every 10 Minutes #

To run a cron job every 10 minutes, add the following line in your crontab file:

*/10  * * * * command

Run a Cron Job Every 15 Minutes #

To run a cron job every 15 minutes, add the following line in your crontab file:

*/15  * * * * command

Conclusion #

We’ve shown you how to run a cron command every 5, 10, or 15 minutes.

Feel free to leave a comment if you have any questions.

cron crontab terminal

Related

Tags: cron, crontab, terminal

How to Install Postman on Linux Desktop

Prev Post

How to Install Windows Subsystem for Linux

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 1
  • 541
  • 612,720

DesignLinux.com © All rights reserved

Go to mobile version