#!/bin/bash

# Call this script from a cron job:
# MAILTO=jody@kaplon.us
# 0,30 * * * * ~/dead-man-qry.bash

# Build in a buffer of 15min to avoid false positives.
NUMHRS=6.25

# set now variable
NOW=$(date -u +"%Y-%m-%d %H:%M:%S")

RESULT=$(sqlite3 /var/www/tenniscourtsopen.com/courtsopen.db "select published_at from Alerts where datetime(published_at) > datetime('${NOW}', '-${NUMHRS} hours') order by datetime(published_at) limit 1")

if [ -z "$RESULT" ]; then
    echo "No data from device in last $NUMHRS hours."
fi