We help IT Professionals succeed at work.

Cron jobs

Hi,

I am trying to figure out cronjobs setup on a linux server.  When i do crontab -u -l , some output displays.  Some jobs have a # in front of them but 1 last job has 0 22 ** 1-5/directory/ cache, etc.

How can I stop all jobs for the 5th ?

Thanks
Comment
Watch Question

Top Expert 2007
Commented:
Here # means line is disabled / ignored as any thing after # means comment.

Your question is not clear "How can I stop all jobs for the 5th ?"

If you mean you wants to run job through 1 to 4 then change line to:

0 22 * * 1-4 /directory/ cache

Author

Commented:
sorry, I mean for just 1 day
Top Expert 2007

Commented:
you mean to stop job for one day ? then comment the line with #

If you mean a particular day of the week or month then you can exclude from range

Author

Commented:
stop for just 1 day;  how can I remove it from this line?

0 22 * * 1-4 /directory/ cache

take out Aug 5th from running
Top Expert 2007

Commented:
there is no straight way. In your script, you can always at the beginning check for date 5 Aug and don't run script.
Top Expert 2007
Commented:
or, you can have two crontab entries:

0 22 1-5 1-7, 9-12 * /directory/ cache
0 22 1-4 8 * /directory/ cache
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
That 1-5 is referring to day of week numbers, where 0=sunday, 1=monday etc.

So if you want to stop all jobs for a certain date, you have to determine the day of week number for that certain date and then adapt the 1-5 to 1-4 for your case (it is a coincidence that Aug 5th is a Friday so day number 5).

A different approach is that you disable the crontab for a user completely by removing the crontab entries and restoring them the next day.

To save entries: crontab -l > your_crontab_file

To remove entries: crontab -r

To restore entries: crontab your_crontab_file

Be sure to check contents of file your_crontab_file before using -r or you'll loose your entries.
Top Expert 2007
Commented:
Hi Gerwin,

The cron tab fields are:

1- min
2- hours
3- day of month
4- month
5- day of week
6- command or script filename

So, 1-5 is the third field and it refers to day of month and not day of week
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
@Omar - No, author is posting:

0 22 * * 1-5

so 1-5 is the fifth field.
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
Eric, any update? Need further assistance?
Top Expert 2007

Commented:
@Gerwin, I thought your comment was about my last post where I recommended to have two crontab jobs:

https://www.experts-exchange.com/questions/28961468/Cron-jobs.html#a41742674
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
@Omar, no it wasn't ;) My suggestion would be to disable crontab for the day and enable again. Not sure if we get a response though since Aug 5th was a week ago...