#!/bin/bash
#

PRO_FILE=/etc/nyquist/protection
ULBIN=/usr/local/bin

function file_age()
{
	local file_to_check
	if file_to_check=$(stat -c %Y -- "$PRO_FILE")
	then
		echo $(( $(date +%s) - $file_to_check))
	else
		return $?
	fi
}

if [[ $# -eq 0 ]] ; then
	echo "0"
	exit 1
fi

if [ ! -f "$PRO_FILE" ]; then
	echo "0"
	exit 0
fi


#file_age

if [[ $(file_age) -lt "30" ]]; then
	$ULBIN/send_mqtt_message protection_mode $1
	echo "1"
	#timestamp=$(date +%s)
	#echo "  Time: $timestamp"
fi


