Files
vigil/scripts/alert
T

31 lines
608 B
Bash
Raw Normal View History

2022-10-27 20:04:45 +00:00
#!/usr/bin/env bash
2023-02-02 15:39:47 +00:00
# Devices to check -- if populated and up, no notifications are sent.
readonly DEVICES=()
2022-10-28 17:16:03 +00:00
readonly RECIPIENT="${NOTIFICATION_RECIPIENT}"
2022-10-27 20:04:45 +00:00
2023-02-02 15:39:47 +00:00
check_devices() {
for device in "${DEVICES[@]}"; do
if ping -c 1 -w 1 "${device}" &> "/dev/null"; then
return 0
fi
done
return 255
}
2022-10-27 20:04:45 +00:00
main() {
2023-02-02 15:39:47 +00:00
# If devices are present, don't notify.
if (( "${#DEVICES[@]}" )); then
if check_devices; then
exit 0
fi
fi
2022-10-27 20:04:45 +00:00
echo "${HOSTNAME}: motion detected at $(date '+%Y-%m-%dT%H:%M:%S%:z')." | \
mutt -s "${HOSTNAME}: Motion Detected" \
-- "${RECIPIENT}"
}
main "$@"