timer

Wake up alarm system
git clone git://git.vgx.fr/timer
Log | Files | Refs

timerat (656B)


      1 #!/bin/sh
      2 #
      3 # Exec a command at a given date (date(1) format).
      4 #
      5 # Dependecies: date, expr, timer (with suid)
      6 
      7 if [ $# -ne 2 ] ; then
      8     echo "Usage: timerat <target_date> <cmd>" >&2
      9     exit 1
     10 fi
     11 
     12 diff_date () {
     13     expr "$(date -d "$1" +%s)" - "$(date +%s)"
     14 }
     15 
     16 #if expr "$1" : '[0-9][0-9]*:[0-9]*$' > /dev/null ; then
     17 #    DAT=$(date -d "tomorrow $1" +%s)
     18 #else
     19 #    DAT=$(date -d "$1" +%s)
     20 #fi
     21 
     22 WAIT=$(diff_date "$1")
     23 if [ "$WAIT" -lt 0 ] ; then
     24     WAIT=$(diff_date "tomorrow $1")
     25 elif [ "$WAIT" -le 0 ] ; then
     26     echo "Can't wake up in the past! (wait: $WAIT sec)" >&2
     27     exit 1
     28 fi
     29 
     30 echo "Waking up in $(date -ud "@$WAIT" +%T)"
     31 
     32 timer "$WAIT" "$2"