arpcheck/arp-checkv2.sh

49 lines
1.1 KiB
Bash
Executable File

TOKEN="A9jDrGFO6Ob-m88"
IP="172.16.1.82"
COUNT_TO_AWAY=900
startedTimeout="n"
away="n"
alertedHome="y"
alertedAway="n"
counter=0
#alert function takes $1 as title, $2 as message. Set TOKEN variable with token.
alert() {
curl -X POST "https://ths.tnet.space/gotify/message?token=${TOKEN}" -F "title=${1}" -F "message=${2}" -F "priority=4"
}
#stdbuf -oL arping "$IP" | while read line
while read line
do
echo "$line"
if [ "$line" = "Timeout" ]; then
if [ "$startedTimeout" = "n" ]; then
startedTimeout="y"
counter=1
echo "$counter"
else
let "counter += 1"
echo "******** $counter"
if [ $counter -eq $COUNT_TO_AWAY ]; then
alert "Status" "Away"
alertedHome="n"
alertedAway="y"
fi
fi
else
if [ "$startedTimeout" = "y" ]; then
if [ "$counter" -ge 100 ]; then
echo "$counter" >> count.hayleyiphone
fi
startedTimeout="n"
counter=0
if [ "$alertedHome" = "n" ]; then
alert "Status" "Home"
alertedHome="y"
fi
fi
fi
done < <(stdbuf -oL arping -W 1 "$IP")