Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setup cron tab to specific time of during weekdays

Tags:

linux

cron

I am trying to setup a cron job on a Ubuntu server. We want the cron job to run the script at certain times of the day and on some specific days of the week. For example, we want to setup a cron job that runs the script with the following sequence:

Execute the script every 2 minutes from 9 am to 2 pm during the weekdays.

This is what I have been able to do so far:

*/2 09-14 * * * /path_to_script

What should I do for the weekdays?

like image 494
Nauman Bashir Avatar asked Jan 21 '13 10:01

Nauman Bashir


People also ask

How do I set up cron to run a file just once at 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.

How do you specify the time zone in cron expression?

Thankfully, you can configure a specific timezone for your Cron job as follows: First, you need to export the TZ variable in your Shell script before any other Shell entries. Next, access your crontab and use the crontab environment variable CRON_TZ at the start of the crontab file.


2 Answers

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

like image 120
ThanksForAllTheFish Avatar answered Sep 21 '22 00:09

ThanksForAllTheFish


You state 2pm in your requirement, hour range should end at 14 instead of 18 (which is 6pm).

*/2 9-14 * * 1-5 /path_to_script 

man crontab

http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

like image 26
EJW Avatar answered Sep 21 '22 00:09

EJW