Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux_wiki:cron [2017/09/03 17:48] billdozor [Automation Example] |
linux_wiki:cron [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 143: | Line 143: | ||
In this example, we want a script to execute on the 1st, 2nd, and 3rd Tuesday of every month, with different arguments depending upon which Tuesday it is. | In this example, we want a script to execute on the 1st, 2nd, and 3rd Tuesday of every month, with different arguments depending upon which Tuesday it is. | ||
- | | + | |
- | | + | |
# | .------------- hour (0 - 23) | # | .------------- hour (0 - 23) | ||
# | | .---------- day of month (1 - 31) | # | | .---------- day of month (1 - 31) | ||
Line 156: | Line 156: | ||
00 08 * * tue root / | 00 08 * * tue root / | ||
</ | </ | ||
- | - Date checker script: Determine if the actual automated program should run and what arguments to send it. | + | |
- | | + | * Date checker script: Determine if the actual automated program should run and what arguments to send it. |
+ | | ||
# Title: automated-job-check.sh | # Title: automated-job-check.sh | ||
# Description: | # Description: | ||
Line 192: | Line 193: | ||
else | else | ||
echo ">> | echo ">> | ||
+ | fi | ||
+ | |||
+ | echo -e "==== Log Ended: $(date) ====\n" | ||
+ | </ | ||
+ | |||
+ | ==== Other Date Check Examples ==== | ||
+ | |||
+ | A few other examples of date checker scripts with relative days before/ | ||
+ | |||
+ | \\ | ||
+ | **7 Days before the first Tuesday of the month**< | ||
+ | # Title: automated-job-check.sh | ||
+ | # Description: | ||
+ | |||
+ | # Script to execute: | ||
+ | script="/ | ||
+ | |||
+ | # Log file | ||
+ | log_file="/ | ||
+ | |||
+ | echo "==== Log Started: $(date) ====" >> ${log_file} | ||
+ | |||
+ | # If today is Tuesday AND 7 days from now is >=1 and < | ||
+ | if [[ " | ||
+ | if [[ $(date +%-d -d "+7 days") -le 7 ]]; then | ||
+ | echo ">> | ||
+ | ${script} 2>&1 >> ${log_file} | ||
+ | else | ||
+ | echo ">> | ||
+ | fi | ||
+ | else | ||
+ | echo ">> | ||
+ | fi | ||
+ | |||
+ | echo -e "==== Log Ended: $(date) ====\n" | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | **2 Days after the third Tuesday of the month**< | ||
+ | # Title: automated-job-check.sh | ||
+ | # Description: | ||
+ | |||
+ | # Script to execute | ||
+ | script="/ | ||
+ | |||
+ | # Log file | ||
+ | log_file="/ | ||
+ | |||
+ | echo "==== Log Started: $(date) ====" >> ${log_file} | ||
+ | |||
+ | # If today is Thursday AND two days ago was >=15 and < | ||
+ | if [[ " | ||
+ | if [[ $(date +%-d -d "-2 days") -le 21 ]]; then | ||
+ | echo ">> | ||
+ | ${script} 2>&1 >> ${log_file} | ||
+ | else | ||
+ | echo ">> | ||
+ | fi | ||
+ | else | ||
+ | echo ">> | ||
fi | fi | ||