#!/bin/bash set -o nounset ### // Sleep until some date/time. # // Example: sleepuntil 15:57; kdialog --msgbox "Backup needs to be done." error() { echo "$@" >&2 exit 1; } NAME_PROGRAM=$(basename "$0") if [[ $# != 1 ]]; then error "ERROR: program \"$NAME_PROGRAM\" needs 1 parameter and it has received: $#." fi CURRENT=$(date +%s) TARGET=$(date -d "$1" +%s) SECONDS=$(($TARGET - $CURRENT)) if [[ $SECONDS < 0 ]]; then error "You need to specify in a different way the moment in which this program has to finish, probably indicating the day and the hour like in this example: $NAME_PROGRAM \"2009/12/30 10:57\"." fi echo "SECONDS=$SECONDS" sleep "$SECONDS" # // End of file