#!/bin/bash


echo starting watchdog, will shutdown within 3 minutes unless host is found...

#wait until host found or timieout
for i in {1..180}
do

    ping -c 1 -w 1 -l 3 -n -q -r -I usb0 10.0.0.2 1>/dev/null 2>/dev/null && break

done

echo host found or timeout, checking again for host...
#shut off hdmi to save power
/usr/bin/tvservice -o


#wait until host not found
while true
do

    ping -c 1 -w 1 -l 3 -n -q -r -I usb0 10.0.0.2 1>/dev/null 2>/dev/null || break

done

echo host not found, halting in 10 seconds...
sleep 10

#turn on hdmi and halt
/usr/bin/tvservice -p
/sbin/shutdown -H now


