Setup Cron Tab to Specific Time of During Weekdays

setup cron tab to specific time of during weekdays

Same as you did for hours:

*/2 09-18 * * 1-5 /path_to_script

0 and 7 stand for Sunday

6 stands for Saturday

so, 1-5 means from Monday to Friday

Run CRON job everyday at specific time

Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis.

Linux Crontab Format

MIN HOUR DOM MON DOW CMD

Sample Image

Example::Scheduling a Job For a Specific Time

The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.

Please note that the time field uses 24 hours format. So, for 8 AM use
8, and for 8 PM use 20.

30 08 10 06 * /home/yourname/full-backup
  • 30 – 30th Minute
  • 08 – 08 AM
  • 10 – 10th Day
  • 06 – 6th Month (June)
  • *– Every day of the week

In your case, for 2.30PM,

30 14 * * * YOURCMD
  1. 30 – 30th Minute
  2. 14 – 2PM
  3. *– Every day
  4. *– Every month
  5. *– Every day of the week

To know more about cron, visit this website.

Different schedule for Weekdays and weekends

I don't know of a way to to this in cron with a single expression. You can do it with 2 lines, though.

0 12 * * 1-5 [your script call]

0 8 * * 6,7 [your script call]

The last column (day of week) can have a range, or a list. Day of week is 1-7 (Mon - Sun), either 0 or 7 can represent Sunday.
HTH

Cron Jobs between x and y on weekdays

Every 10 minutes between 09:00 - 17:00 on weekdays (monday - friday)

*/10 09-17 * * 1-5 /path/to/file

cron expression to run a job every hour but only on weekdays?

You can do it like this:

0 * * * 1-5

This website is really good for CRON scheduling:
https://crontab.guru

How can I create Cron Expression which works between particular times

Some things you cannot do in a single expression and you might consider to use two:

# Example of job definition:
# .--------------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
# This runs on 7:30, 7:40, 7:50
30/10 7 * * 1-5 command
# This runs on 8:00, 8:10, 8:20
0-20/10 8 * * 1-5 command

Another way you could attempt this is by using a test.

# Example of job definition:
# .--------------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
*/10 7,8 * * 1-5 testcmd && command

Where testcmd is an executable script that could look like:

#!/usr/bin/env bash
hours=$(date "+%H")
minutes=$(date "+%M")
(( hours == 7 && minutes >= 30)) || (( hours == 8 && minutes <= 20 ))

Other examples of this trick can be found here:

  • Cron expression to run every N minutes
  • How to schedule a Cron job to run 4th week of the year
  • how to set cronjob for 2 days?


Related Topics



Leave a reply



Submit