fix date parsing for macOS (Darwin)

fix usage diagnostic and output to stderr
This commit is contained in:
Jan-Piet Mens 2017-09-05 20:44:20 +02:00
parent 6dec919e09
commit 23b67272b5

View file

@ -5,7 +5,7 @@ set -uo pipefail
#backup li
display_usage() {
echo -e "Usage: ./backup <repo> (local|monitor <host> <warning> <critical>|restic arguments) \n"
echo "Usage: $0 <repo> (local|monitor <host> <warning> <critical>|restic arguments)" >&2
}
if [ "$#" -lt 2 ]; then
@ -91,7 +91,14 @@ do_monitor () {
# Compute time difference since last snapshot
case $(uname -s) in
Darwin)
BACKUP_TST=$(date -j -f "%Y-%m-%d %H:%M:%S" "$DATE $TIME" "+%s")
;;
*)
BACKUP_TST=$(date -d "$DATE $TIME" +"%s" )
;;
esac
NOW_TST=$(date +%s)
DIFF_S=`expr $NOW_TST - $BACKUP_TST`