I want run a cron job which will run every 20 day of every month and on monday.
From one monday to another monday there should be gap of 20 days.
For example -
If the cron job run on this month monday
means on 12th of oct then the next job will be running on 2nd of nov and on monday.
Help me out. I trying but not able to achieve this.
May be this tool can help you: crontab.guru
if I understand your question is something like this:
#+--------------------------- Minute (0-59)
#| +---------------------- Hour (0-23)
#| | +---------------- Day (1-31)
#| | | +------------ Month (1-12)
#| | | | +-------- Day of week (0-6, 0=Sunday)
#| | | | | +--- Command to be run
#| | | | | |
#v v v v v v
#====================================================================
# run task At 00:00 on Monday.
0 0 * * 1 run_task.sh
In run_task.sh you can put the condition.
# script to check if the task run 20 days ago.
aux_file="/tmp/auxdate.txt"
# this compare the actual date with the date in the file
# if the diference is >= 20 the task run
if [[ ! -e "$aux_file" || $(( ($(date '+%s') - $(cat auxdate.txt))/(60*60*24) )) -ge 20 ]]; then
echo $(date '+%s') > "$aux_file"
echo "RUN TASK"
# run task...
else
echo "NOT RUN TASK"
fi
Related
I'm looking to create a shift schedule sheet for my team. This is what I've got so far:
How do I calculate the total hours for the 7 days in between those times?
Thanks
How about splitting starting time and end time in two columns such as:
| Monday | Tuesday | ...
| 9am | 5pm | 9am | 5pm | ...
Then if you do an arithmetic operation, you'll have a result in days. So simply multiply by 24:
1 | A | B | C | D |
2 | Monday | Tuesday | ... |
3 | 9am | 5pm | 9am | 5pm | ... | =24*( (B3-A3) + (D3-C3) ...)
Tested in Excel 2013:
Provided that A3, B3, C3... are times. Formatting is up to you obviously.
I need to generate cron expression for every 10 min in the date range October 2017 to Feburary 2018.
I tried the following expression:
0 10 0 ? 10-2 * 2017-2018,
But its not a valid expression. I get this error message:
((Month) - Unsupported value '10-2' for range. ),
Please help.
Try to use this:
*/10 * * 2-10 * 2017,2018 command here
from nncron.ru page:
* * * * * *
| | | | | |
| | | | | +-- Year (range: 1900-3000)
| | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month (range: 1-31)
| +---------- Hour (range: 0-23)
+------------ Minute (range: 0-59)
if you want to test other format, use this page http://cronsandbox.com/
I have read the CronFormat to understand the Cron.But I am unable to understand this Cron Format:
According to my understand,the format is
<Minute> <Hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week>
But I am unable to understand the below format.
07/10 * 1/1 *?*
My Understanding:
My understanding of the above format is:
After Every 7 Minute,every hour and every month and every year.
Can anyone guide me what is it?
QuestionMark(?) and * I have not understood
This is format of each cron job
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
so 7/10 means 7th minute of every 10 minute,
next * means every hour,
1/1 also means every so every day.
Unfortunately I am also not aware of "?".
I like this example its easy for me to understand :-
# Minute | Hour | Day of Month | Month | Day of Week | Command
# (0-59) | (0-23) | (1-31) | (1-12 or Jan-Dec) | (0-6 or Sun-Sat)
0 | 2 | 12 | * | * | /usr/bin/find
I would like to set up a cron task to run a script every first day of every month except 1st january. How can I do that?
Could I try something like that: 0 0 1 2-12 * ?
It can be something like below:
0 0 1 2,3,4,5,6,7,8,9,10,11,12 *
Minutes [0-59]
| Hours [0-23]
| | Days [1-31]
| | | Months [1-12]
| | | | Days of the Week [Numeric, 0-6]
| | | | |
* * * * * home/path/to/command/the_command.sh
This is can be usefull for you to identify the usage.
I need to run bash script at 2nd Sat of the month at 11pm.I cant figure out its cronformat.
* * * * * *
| | | | | |
| | | | | +-- Year (range: 1900-3000)
| | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month (range: 1-31)
| +---------- Hour (range: 0-23)
+------------ Minute (range: 0-59)
This is the cronformat i found from the internet but i am new to this and i think this problem is kind of tough.
Arg i waited so many days for the solution but not a single comment nor an answer. Anyway i think the answer is
0 23 8-14 * Sat
please correct me if i am wrong.
Run the cron every Saturday and only execute the script on the second Saturday:
* * * * 6 * test $(expr $(date +\%d) / 7) -eq 2 && <execute script here>