Can we stop the cronjob for 6-7 hrs each day? - cron

I have written the cronjob that runs each hour. Can we anyway stop the cronjob for 6-7 hrs each day ? Example : My cronjob runs a script each hour to fetch the traffic count on hourly basis. Now, during night, between 01:00 and 07:00 hrs,no transactions takes place and hence no count traffic. This can sometimes be misleading as if the system is down for 6 hrs each day (since the script sends an email if nothing is fetched for 1 hr). To improve that i want my cronjob to stop for 6 hrs between 01:00 and 07:0 hrs each day. So, can you please advise if we can do so ?

Why not just define which hours the cronjob should run?
0 0,8-23 * * * /my/command
A crontab entry like that would run at midnight and the hours between 0800 and 2300

Related

Cron job one schedule for 3rd Sunday but different schedule every other day

We have jobs that are scheduled to run 1 time per day - every day
We do maintenance every 3rd Sunday of the month.
Up until now every month we have manually adjusted the cron to make the job run a little later in the morning then after maintenance we reset to the desired schedule
I am trying to change cron so that we
run at 7:00am every day EXCEPT the third Sunday of the month
run at 9:00am only on the third Sunday of the month
the second item I am able to handle
0 13 15-21 * 0
however, the first has me stumped. I thought this would do the job but it will only execute this if the day is between 1-14 or 22-31 but what if the 15th is not Sunday - then it won't run.
0 11 1-14,22-31 * *
How do I tell cron to run a schedule EXCEPT the third Sunday of the month?
There is a large base of guidance on how to limit when a cron runs to a specific window but I haven't found much for how to EXCLUDE a cron from a specific window
******** UPDATE ********
I think I may have come up with an answer - not sure if it is the most efficient but
0 11 1-14,22-31 * 0
0 13 15-21 * 0
0 11 1-14,22-31 * 1-6
The above will
run at 11:00 UTC on Sunday if date is between 1-14 or 22-31
run at 13:00 UTC on Sunday if date is between 15-21 (3rd Sunday)
run at 11:00 UTC Monday through Saturday all month
If a cron job has different timing than others, then it best to just define it by itself rather than trying to combine, unless you put some code in your script to do what you actually want. Doing something in cron on some nth day of the month is a pretty well known problem. Most crontab man pages have this note:
Note: The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the crent time. For example,
"30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
So it does OR between the day of the week and the day of the month, not an AND. I don't who ever thought this was helpful, but that's the way it is. You can see solutions at:
Run every 2nd and 4th Saturday of the month
you need something like (this assumes cron runs /bin/sh):
[ `date +\%w` -eq 6 ] && <command>
on your cron job line, the above is would restrict to running only on Saturday.

How to set cron every 2 minutes but only for 4 hours starting at 12:00 AM

I need a cron job that start at 12:00 AM and trigger the job every 2 minutes but only until 4:00 AM.
With this command I have to triggers another cron job that is very heavy and often killed by my server, so with this command every 2 minute the server is forced to resume the job.
Minute Hour Day Month Weekday Command Actions
*/2 0,14 * * *
Cron job every 2 minutes for 4 hours, every day, starting at 12:00 AM.

Cron job for every weekday at 6 am

I was wondering if anyone knew how to create a cron job that runs from monday to friday at 6am.
I am using gitlab CI, quickly looked at the example syntax and am not exactly sure how to limit it to occur from monday to friday.
Not sure what about gitlab CI, but cron syntax is minute, hour, day of month, month, day of week, meaning job which should run every week day from 6am is
0 6 * * 1-5

How to set Chronos job schedule to run only 4 times every day?

We have a requirement where a particular chronos(https://mesos.github.io/chronos/) job has to be run every 3 hours a day starting from morning 8 AM. So total 4 runs i.e. 8AM, 11AM, 2PM, 5PM and no runs after that. It should repeat every day. How to set such schedule in Chronos? Is it possible?

can't get the right cron job timing

i'm trying to do some stuff automatically every 8 Weeks, so i had open a new user crontab like this one:
crontab -e
0 9 * */2 1-5 do_this_stuff
# do it every 2 month on monday till friday at 9:00 am
This should do the job every 2 month on monday till friday on 9:00 am, but i does not. It is doing the job evey week once. Don't get it. What i'm doing wrong?
Running System is a latest debian.
regarding http://wiki.ubuntuusers.de/Cron it should run fine
The Anwer is, cron can't do a job randomly on a random day in a month. I had to change my crontab to: 0 9 1 */2 * do_sm_stuff -- this runs every two Month always on the first Day in a Month
thank you Igor

Resources