I have a similar situation. My goal is to have a solution which is very simple for non-unix geeks to maintain.
When my Linux server restarts, it runs a script which sends an alert. But if this happens as part of our"Maintenance Window" which is defined as between 11pm Saturday and 6am Sunday, I do not want to send the page, because a restart during this window is Okay (patches applied, etc.). I have tested it and it does work as intended (as far as I can tell).
Here is the calendar for reference:
June 2018
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Here is my test code:
FMT='+%k:%a' # i.e. Sat:23 for Saturday at 11pm local time
TESTDATE1=$(date -d '2018-06-23 14:30:00' $FMT)
TESTDATE2=$(date -d '2018-06-23 23:59:59' $FMT)
TESTDATE3=$(date -d '2018-06-24 00:00:00' $FMT)
TESTDATE4=$(date -d '2018-06-24 05:59:59' $FMT)
TESTDATE5=$(date -d '2018-06-24 08:01:00' $FMT)
for VAL in "${TESTDATE1}" $TESTDATE2 $TESTDATE3 $TESTDATE4 $TESTDATE5
do
#extract the 24 hour value and the day
HH="$(echo ${VAL} | cut -d':' -f1)"
DAY="$(echo ${VAL} | cut -d':' -f2)"
echo Testing $VAL $HH $DAY
if [[ "$DAY" = "Sat" && $HH -ge 23 ]]; then
echo ' Shhhh People are trying to sleep ... Sat window'
elif [[ "$DAY" = "Sun" && $HH -le 6 ]]; then
echo ' People are trying to sleep ... Sun window'
else
echo ' PAGE SOMEONE - time is outside the Maintenance Window'
fi
done
Here is the output
Testing 14:Sat 14 Sat
PAGE SOMEONE - time is outside the Maintenance Window
Testing 23:Sat 23 Sat
Shhhh People are trying to sleep ... Sat window
Testing 0:Sun 0 Sun
People are trying to sleep ... Sun window
Testing 5:Sun 5 Sun
People are trying to sleep ... Sun window
Testing 8:Sun 8 Sun
PAGE SOMEONE - time is outside the Maintenance Window