C
C
cobb2021-05-27 11:14:34
bash
cobb, 2021-05-27 11:14:34

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

4 answer(s)
V
Vladimir Kuts, 2021-05-27
@cobb

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

V
Vladimir Korotenko, 2021-05-27
@firedragon

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

V
Vladimir, 2021-05-27
@MechanID

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.

C
CityCat4, 2021-05-27
@CityCat4

In krone as far as I know - it is impossible. Will have to check directly in the script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question