#!/bin/bash
# added to rc.local because sometimes the network can not be found during boot-process and
# rc.local will start my network watchdog script: /usr/script/networkwd.sh
#
# Both files (rc.local and networkwd.sh) are made by Fred Bogus Trumper:
# Thread is here: http://dreambox.de/board/index.php?thread/23313-dreamos-dm900-manchmal-kein-netzwerk-nach-einem-reboot/#post199565
#
SCRIPT="/usr/script/networkwd.sh"
[ -d /media/hdd/log ] && LOGFILE="/media/hdd/log/networkwd.log" || LOGFILE="/media/hdd/log/networkwd.log"

for i in /usr/script /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin:/sbin; do
  [[ ! ${PATH} =~ ${i} ]] && PATH="${PATH}:${i}"
done

networkwd () {
  sleep 5
  [ ! -f ${SCRIPT} ] &&   echo -n `date +"%b %d %H:%M:%S"` >> ${LOGFILE} && echo " $(hostname) - ${SCRIPT} not found" >> ${LOGFILE} || ${SCRIPT} >> ${LOGFILE}
}

networkwd &
exit 0#!/bin/bash
JOURNALDUMP=/media/hdd/log/network_journal.log
# IP = Router IP, Goolge DNS etc.
IP=192.168.1.1

getdate () {
echo $(date +"%b %d %H:%M:%S") $(hostname)
}

while true
do
        if ping -c 1 -w 1 $IP >/dev/null; then
                echo "$(getdate) - network watchdog: network connection ok"
                exit 1
        else
                echo "$(getdate) - network watchdog: network connection not ok! ping failed"
                echo "$(getdate) - network watchdog: dump journal to $JOURNALDUMP"
                journalctl -x > $JOURNALDUMP
                echo "$(getdate) - network watchdog: restart socket.target and connman.service"
                systemctl restart socket.target
                sleep 1
                systemctl restart conmann.service
        fi
done

exit 0