Skip to content

Instantly share code, notes, and snippets.

@ikucuze
Created February 28, 2024 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikucuze/0af4ac30ccfdee044f13a730c84686ef to your computer and use it in GitHub Desktop.
Save ikucuze/0af4ac30ccfdee044f13a730c84686ef to your computer and use it in GitHub Desktop.
script qui surveille les jours Tempo ROUGE edf, et appelle une commande en debut et fin de la plage heure pleine (pour verrouiller un appareil énergivore par ex)
#! /bin/bash
while true ; do
hour=`date +%H`
today=`date +%F`
if [[ 10#$hour -ge 22 ]] ; then
echo after 10pm, check tomorrow
nowEpoc=`date +%s`
nowEpoc=$(($nowEpoc + 86400 ))
today=`date -d @$nowEpoc +%F`
fi
echo check: $today
out=`wget -q -O - https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant=$today`
couleur=`echo $out | jq -r .couleurJourJ`
couleurDemain=`echo $out | jq -r .couleurJourJ1`
echo "couleur: $couleur (demain: $couleurDemain)"
if [[ $couleur == "TEMPO_ROUGE" ]] ; then
nowEpoc=`date +%s`
today6Epoc=`date -d "$today 06:00" +%s`
sec=$(($today6Epoc - $nowEpoc))
if [[ $sec -gt 0 ]] ; then
echo sleep before lock at 6am: $sec
sleep $sec
fi
######
### INSERT HERE ANY COMMAND TO RUN AT 6am ON RED DAYS
######
nowEpoc=`date +%s`
today22Epoc=`date -d "$today 22:00" +%s`
sec=$(($today22Epoc - $nowEpoc))
if [[ $sec -gt 0 ]] ; then
echo sleep before unlock at 10pm: $sec
sleep $sec
fi
######
### INSERT HERE ANY COMMAND TO RUN AT 22pm ON RED DAYS
######
else
echo OK, Wait 5h from `date +%R`
sleep 18000
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment