#!/bin/sh
# inetup.sh
# 2010-05-20
# by Gernot Walzl
# Checks for an active internet connection by pinging a given host.
# If the host is down, it reconnects. A log file is written for all conditions.
HOST="www.google.at"
LOGFILE="/root/inetup.log"
NOW=$(date +"%Y-%m-%d %H:%M:%S")
ping -c 1 "$HOST" > /dev/null
if [ "$?" -ne "0" ]; then
echo "$NOW - Internet is down. reconnecting" >> "$LOGFILE"
/usr/sbin/ppp-off
sleep 3
killall pptp
sleep 3
/usr/sbin/pptp 10.0.0.138
else
IP=$(ifconfig ppp0 | grep 'inet addr:' | awk '{print $2}' | cut -c 6-)
echo "$NOW - Internet is up. ($IP)" >> "$LOGFILE"
fi