#!/bin/sh

ONLINE=1

. /usr/bin/fonction.sh



while :; do
source /etc/ip_config
source /etc/ip_machine	
if [ $IS_IP_ADR = 1 ]; then
  ping -q -c 3 $IP_MACHINE > /dev/null
else
  ping -q -c 3 $SERVER_IP > /dev/null
fi


#ping pas réussi
  if [ $? = 1 ]; then
	if [ ! -e /home/CAPELEC/DATA/offline.state ]; then
		log "ERROR: Offline"
		touch /home/CAPELEC/DATA/offline.state 
	fi

		ONLINE=0
#ping réussi
  else
    if [ $ONLINE = 0 ]; then
	rm /home/CAPELEC/DATA/offline.state 
	log "Online"
      ONLINE=1
    fi
  fi


#montage reseau si echec dans start.sh
if [ ! -e "/home/CAPELEC/DATA/mount.state" ]; then
		if [ $ONLINE = 1 ]; then			
		      restart_lan
		fi
fi

  #echo $ONLINE
  sleep 10
done
