La liaison internet entre votre ordinateur et votre box n’est pas stable ? Voici un script qui vous permettra (sous Linux) de vérifier cette connexion et éventuellement de reconnecter votre ordinateur.
[pastacode provider= »manual » lang= »bash » message= »reconnexion.sh »]
#!/bin/sh
# Vérification connexion
# Configuration
GATEWAY=192.168.1.1 # adresse de la box
NOEUD=1 # Nombre de noeud du réseau
LOG="/var/log/wifi_reload.log"
# Témoin de connexion
ping -c ${NOEUD} ${GATEWAY} ;
# Test
if [ "$?" == "0" ]
 then
	# Verification OK donc on ne fait rien
	echo  "`date +%Y-%m-%d-%H:%M` : Box ${GATEWAY} OK" >> $LOG;
 else
	# Pas de réponse au ping donc on  relance de la config wifi
	echo "`date +%Y-%m-%d-%H:%M` : Connexion box ${GATEWAY} rompue. Tentative de reconnexion" >> $LOG;
	service networking restart;
	sleep 5;
	ping -c ${NOEUD} ${GATEWAY} ;
		if [ "$?" == "0" ]
		 then
			echo  "`date +%Y-%m-%d-%H:%M` : Box ${GATEWAY} operationnelle" >>$LOG;
 		 else
			echo "`date +%Y-%m-%d-%H:%M` : Box ${GATEWAY} toujours pas connectée">>$LOG;
		fi 
fi
[/pastacode]
Ensuite, mettez ce fichier dans /usr/local/bin et rendez ce fichier exécutable :
[pastacode provider= »manual » lang= »bash »]
chmod +x /usr/local/bin/reconnexion.sh[/pastacode]
Faites ensuite tester votre connexion (toutes les 5 min par exemple) en ajoutant cette ligne dans votre fichier /etc/crontab :
[pastacode provider= »manual » lang= »bash »]
*/5 * * * * 	root	bash /usr/local/bin/reconnexion.sh[/pastacode]
Vous pouvez vérifier régulièrement ce qu’à fait ce script (et quand) en consultant le fichier /var/log/wifi_reload.log
 Follow
 Follow