user
How to schedule a cron job at every five minutes?
alphonsio

To schedule a cron job at every five minutes, use the following syntax:

 */5  *  *  *  * 	user-name 	/path/to/command
# |   |  |  |  |
# |   |  |  |  .---- Every day of the week
# |   |  |  .------- Every month
# |   |  .---------- Every day
# |   .------------- Every hour (* = any value)
# .----------------- Every five minutes (/ = step values)

To schedule a cron job to run every five minutes, you would use the following cron expression:

*/5 * * * *

Breakdown of the Cron Expression:

  • */5 — Every five minutes
  • * — Every hour
  • * — Every day of the month
  • * — Every month
  • * — Every day of the week

Steps to Add the Cron Job:

  1. Open the terminal.

  2. Type crontab -e to edit the cron jobs for the current user.

  3. Add your cron job using the above expression followed by the command you want to run. For example, to run a script located at /path/to/your/script.sh, you would write:

    */5 * * * * /path/to/your/script.sh
    
  4. Save the file and exit the editor.

Example Command:

If you wanted to run a Python script every five minutes, it might look like this:

*/5 * * * * /usr/bin/python3 /path/to/your/script.py

Notes:

  • Ensure that the script has executable permissions (you can set this with chmod +x /path/to/your/script.sh).
  • You can check the logs of the cron job in /var/log/syslog (on some systems) to see if it is executing as expected.