Voici un petit script trivial en bash qui, couplé à cron, me permet de maintenir ma connexion internet 56kbps fournie par Free.fr (en attendant l’arrivée du modem ADSL):
1#!/bin/bash2# Script de reconnection automatique34testconnect() {5CONNECT=`ping -c 3 google.com | grep packets | cut -d' ' -f4`6}78doconnect() {9logger -t reconnect Essai reconnection.10/etc/init.d/internet restart11}1213displayip() {14IP=`/sbin/ifconfig | grep -A 1 ppp0 | grep inet | cut -d' ' -f12 | cut -d':' -f2`15logger -t reconnect Adresse IP : "$IP"16}1718logger -t reconnect Test connection.19testconnect20if [ "$CONNECT" = "0" ];21then22logger -t reconnect Connection perdue.23doconnect24testconnect25if [ "$CONNECT" != "0" ];26then27logger -t reconnect Reconnection OK.28displayip29else30logger -t reconnect Reconnection manquee.31fi32else33logger -t reconnect Connection OK.34displayip35fi3637exit 038# FIN