Answer the question
In order to leave comments, you need to log in
How to set a bash script to run on its own schedule?
Good afternoon. Prompt, please, who faced such task? It is necessary to set the script execution schedule, but only on weekdays, if I can cut off Saturday and Sunday with CRON, then what about the holidays? For example May, New Year's holidays? Is it possible to pre-set days in CRON on which the script does not run? Or it is necessary to implement it in script logic?
Answer the question
In order to leave comments, you need to log in
In the file holidays.txt, write out the holidays according to the production calendar in the format %d.%m.%y
Check the current date at startup
#!/bin/bash
if cat holidays.txt | grep `date +"%d.%m.%y"` > /dev/null ; then
# выполнять если праздник
else
# выполнять если не праздник
fi
Only with the help of logic. That is, I would do this: the script is in the cron, but it reads a text file with holiday dates when it starts. You fill in this same file either by hand or using the api of the same 1s
As far as I know cron does not support exceptions and the like.
At one time, I just made a text file into which it was easy to add holiday dates, and the cron script ran all working days and first of all checked if the current day was in this file, if so, then completed its work. Also, with this option, you need a reminder in the calendar - fill out this file once a year.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question