scripts / rtcwake /
Newer Older
43 lines | 1.517kb
ajout rtcwake pour réveil de...
Sébastien MARQUE authored on 2019-01-05
1
#!/bin/bash
2
# /lib/systemd/system-sleep/rtcwake
3
# chmod a+rx
4

            
5
set -e
6

            
7
AWAKE_TIME="01:23:45" # hour:minute:second
8
GAP="10 seconds"      # precision of awake time in date(1) format
9
WAIT_TRIGGER='true'   # test to go back to sleep when action is finished 
10
                      # typically pgrep on user or for specific process
11
WAIT_TRIGGER_DELAY=60 # sleep duration in seconds between two tests with WAIT_TRIGGER
12
MAX_TRIGGER=60        # don't go back to sleep if WAIT_TRIGGER isn't true
13
                      # after WAIT_TRIGGER_DELAY * MAX_TRIGGER seconds
14

            
15
test -r $0.conf && source $0.conf # all previous variables can be set here
16

            
17
NOW=$(date +%_H%M%S)
18
RTCWAKE_TIME=$([ $NOW -lt ${AWAKE_TIME//:} ] && date +%s -d $AWAKE_TIME || date +%s -d "tomorrow $AWAKE_TIME")
19

            
20
case "$1/$2" in
21
    pre/suspend)
22
        rtcwake -m no -t $RTCWAKE_TIME
23
        ;;
24
    post/suspend)
fix post sleep
Sébastien MARQUE authored on 2019-01-06
25
        at -M now <<< "$0 post wait-for-trigger" > /dev/null 2>&1
26
        ;;
27
    post/wait-for-trigger)
ajout rtcwake pour réveil de...
Sébastien MARQUE authored on 2019-01-05
28
        if test $NOW -ge ${AWAKE_TIME//:} -a $NOW -le $(date +%_H%M%S -d "$AWAKE_TIME $GAP"); then
29
            COUNT=1
30
            while sleep $WAIT_TRIGGER_DELAY && eval $WAIT_TRIGGER; do
envoi d'un mail en cas de no...
Sébastien MARQUE authored on 2019-02-17
31
                let COUNT++ && [ $COUNT -lt $MAX_TRIGGER ] || {
erreur dans la conf
Sébastien MARQUE authored on 2019-02-25
32
                    if test -n "$ON_ERROR"; then
33
                        eval "$ON_ERROR"
fix: sortie de boucle imposé...
Sébastien MARQUE authored on 2019-02-26
34
                        break
envoi d'un mail en cas de no...
Sébastien MARQUE authored on 2019-02-17
35
                    fi
36
                }
ajout rtcwake pour réveil de...
Sébastien MARQUE authored on 2019-01-05
37
            done
38
            rtcwake -m mem -t $RTCWAKE_TIME
39
        else
40
            rtcwake -m disable
41
        fi
42
        ;;
43
esac