Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip the cron job in saturday and sunday in linux? [closed]

Hi I want to create a cron expression excluding saturday and sunday.

like image 747
Rakesh Sabbani Avatar asked Feb 04 '12 19:02

Rakesh Sabbani


People also ask

How do I stop a cron job at a certain time?

You could use a second cron job at 09pm to start a second program that tells the first program to terminate. There are a number of ways to do this. One of the easiest might be to have the second program touch terminate. txt in a convenient place.

How do I stop a scheduled cron job in Linux?

You can stop a single cron job by removing its line from the crontab file. To do that, run the crontab -e command and then delete the line for the specific task. Alternatively, you can stop the cron job by commenting it out in the crontab file.

What does 0 * * * * mean in crontab?

0 * * * * -this means the cron will run always when the minutes are 0 (so hourly) 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.

How disable and enable crontab in Linux?

The quickest way would be to edit the crontab file (which can be done by typing crontab -e ) and simply comment the job you want disabled. Comment lines in crontab start with a # . For others wondering, the command crontab -e will open the text editor for the current users crontab file.


2 Answers

Begin the line with 0 0 * * 1,2,3,4,5 <user> <command>. The first fields are minutes and hours. In this case the command will run at midnight. The stars mean: for every day of the month, and for every month. The 1 to 5 specify the days. monday to friday. 6=saturday 0=sunday.

like image 159
Michel Avatar answered Sep 21 '22 09:09

Michel


Try this:

# run every two hours at the top of the hour Monday through Friday 0 */2 * * mon-fri <command> 
like image 38
SiegeX Avatar answered Sep 21 '22 09:09

SiegeX