Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cron jobs

Posted on 2016-08-04
12
Medium Priority
?
173 Views
Last Modified: 2016-08-21
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
0
Comment
Question by:Eric Donaldson
  • 6
  • 4
  • 2
12 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 2000 total points
ID: 41742529
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
0
 

Author Comment

by:Eric Donaldson
ID: 41742589
sorry, I mean for just 1 day
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 41742601
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Eric Donaldson
ID: 41742614
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
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 41742659
there is no straight way. In your script, you can always at the beginning check for date 5 Aug and don't run script.
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 2000 total points
ID: 41742674
or, you can have two crontab entries:

0 22 1-5 1-7, 9-12 * /directory/ cache
0 22 1-4 8 * /directory/ cache
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41751165
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.
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 2000 total points
ID: 41751441
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
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41751699
@Omar - No, author is posting:

0 22 * * 1-5

so 1-5 is the fifth field.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41754129
Eric, any update? Need further assistance?
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 41754584
@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
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 41754606
@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...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question