how can we modify cron expression to not to run on specific date, say 28th Dec and 3rd February - cron

I already have a cron expression as : " 35 6 * * 2-6 ", which states the
job will run every morning 6:35 from tuesday to saturday.
I want to exclude 28th Dec and 3rd Feb from this expression.
We are evaluating this cron expression in java code.
These expressions are for jobs written in java.
There is a parent job A.
It has two child jobs A1 and A2.
For job A to run, both A1 and A2 should be successful.
I need to configure this exceptional date parameter for A1 and A2 with
existing cron condition.
Both A1 and A2 should not run on 28th Dec and 3rd Feb.
Can anyone please assist.

You could split your cronjob into three:
35 6 * 1,3-11 2-6 A1.sh && A2.sh
35 6 1-2,4-28 2 2-6 A1.sh && A2.sh
35 6 1-27,29-31 12 2-6 A1.sh && A2.sh
Where A1.sh and A2.sh are shell script that would execute your child jobs A1 and A2. Make sure the shell scripts have the right permission.

Related

Need Quartz Cron Expression to run scheduler every 4 hours starting at 00:30 am

Quatz cron to run the job at 12:30am, 4:30am, 8:30am, 12:30pm, 4:30pm 8:30pm everyday
Can someone please help with this
The expression you search for is:
0 30 0,4,8,12,16,20 * ? * /path/to/command
This will run 30 minutes from every hour in list

Unix Cron for running job on 1st weekday

Can someone help mw with the cron expression for running job on 1st weekday??
Is it possible in simple unix crontab?
If your week start on Monday and you want to run script every monday you should use something like (suppose you run your script at 22h 00m)
0 22 * * 1 /path/to/script
If you want to run the script first work day of month and your week start on Monday you can try something like:
0 22 1,2,3,4,5,6,7 * * /path/to/script
and add on the begin of the script this:
if [ "$(date +%u) -ne 1 ]
then exit
fi
this will end the script if you run it on day of week which is not Monday

Crontab not running on sunday night

So I made this so it would send a command at Sunday night at 11:59pm, 1 minute before Monday, but for some reason it doesn't work. I even changed the * * 7 to 0.
59 23 * * 7 screen -S skyblock -p 0 -X stuff "mangdelp default essentials.fly ${printf \\r)"
Your syntax is incorrect.
It should be like this:
59 23 * * 0 screen -S skyblock -p 0 -X stuff \"mangdelp default essentials.fly ${printf \\r)\" >/dev/null 2>&1
minute(s) hour(s) day(s) month(s) weekday(s) command(s)
The fields are
separated by spaces or tabs. The first five are integer patterns and
the sixth is the command to be executed. The following table briefly
describes each of the fields.
Field Value Description
minute 0-59 The exact minute that the command sequence executes
hour 0-23 The hour of the day that the command
sequence executes
day 1-31 The day of the month that the command
sequence executes
month 1-12 The month of the year that the command
sequence executes
weekday 0-6 The day of the week that the command
sequence executes. Sunday=0, Monday = 1, Tuesday = 2, and so forth.
command Special The complete sequence of commands to be executed. The
command string must conform to Bourne shell syntax. Commands,
executables (such as scripts), or combinations are acceptable.

Special crontab expression

just to verify my understanding of cron-syntax, the following expression will fire on a saturday at 02:42 in the middle of the month, right?
42 02 12-19 * 6 myScript > /dev/null 2>&1
cheers
Nicolaie
The script myScript (not good without a path here!) will be executed at 2:42 indeed, on every day between and including the 12th to the 19th of each month that is a saturday.
Actually
42 02 12-19 * 6 myScript > /dev/null 2>&1
means run on 12 thru 19 and every Saturday.
You need a more complex line to do what you state:
0 4 8-14 * * test $(date +\%u) -eq 6 && echo "2nd Saturday"
is an example from the manfile on my system. It uses a trivial execution after making sure it is Saturday.
See http://www.adminschoice.com/crontab-quick-reference/ as well as > man 5 crontab (at the commandline) for more.

Create Cron job to execute every wed at 2nd week

What the correct way to execute cron job to be run at
Wed in 2nd / week and wed in 4th week of each month
any tips
Following would run the job on every wednesdays at 11 AM
00 11 * * 3 <your-command>
Here the 3 says, the command to run every Wednesday. You would need to create a wrapper script, to just skip the execution on alternate Wednesday, and call that script from above cron.

Resources