|
From: Manu E. <ee...@ma...> - 2003-05-23 02:17:11
|
Hi Friedrich,
this is quite a Bad bash script (i'm not a developper !) but it works
... sure you can easily improve !
* I use rp-pppoe to connect to the internet 24/24.
* I write a script /etc/ppp/adsl-lost wich is called by
/usr/sbin/adsl-connect each time pppd dies; it simply call update_dyndns
script, but could be used for other stuff to do when Adsl link comes
down (ex change route to use an isdn link as backup ... etc)
* also create a script (from the skeleton) /etc/init.d/adsl to
start/stop/restart adsl link : it simply call /usr/sbin/adsl-start and
then update_dyndns
(started with 0.5b6 ... there was none ... )
* add $WAN_HOST in the /etc/sysconfig/config file to store the dyndns
name for that host
* get_inet_addr and get_ddns_addr are standalone scripts as i use them
for other things. (i know these are bad ;-) )
Comments are welcome ! but don't be too malicious, i'm sensitive ;-)
MaNU
----------------
#!/bin/sh
# script execute quand on remonte le lien adsl
#
# /root/sbin/update_dyndns
#
source /etc/sysconfig/config
logger -p info "Lien ADSL en cours de (re)connexion ... "
if ! [ -f /var/run/adsl-lost.pid ]; then #si le process
n'est pas déja en train de tourner ...
echo "1" > /var/run/adsl-lost.pid
logger -p info "On boucle jusqu'a ppp0 .... "
until [ -d /proc/sys/net/ipv4/conf/ppp0 ] #on boucle
jusqu'a ce que ppp0 soit up ...
do
logger -p info "On attend 1 Minute de plus ... "
sleep 60
done
logger -p info "L'ADSL est de Retour .... "
# on teste si l'ip a change
until test "$MY_DDNS" != ""; do
sleep 1
MY_DDNS=`/root/sbin/get_ddns_addr`
done
until test "$MY_INET" != ""; do
sleep 1
MY_INET=`/root/sbin/get_inet_addr`
done
if test $MY_INET != $MY_DDNS ; then
# l'IP a CHANGE, on a un certain nombre de choses a
mettre a jour
logger -p info "L'adresse a changée : $MY_DDNS =>
$MY_INET .... "
# en commencant par le dynamic DNS
/usr/sbin/ddup --host $WAN_HOST | logger -p info
sleep 5 # un petit delai pour la propagation de la
nouvelle adresse
# puis on recharge les regles du firewall pour prendre
en compte le changement
/usr/bin/setsid /etc/init.d/firewall reload
else
logger -p info "L'adresse est inchangée : $MY_DDNS ==
$MY_INET .... "
fi
rm /var/run/adsl-lost.pid
fi
----------------
----------------
#!/bin/sh
#
# /root/sbin/get_inet_addr
#
ifconfig ppp0 | awk '/inet addr:/ {print $2}' | awk '// {print $2}' FS=":"
----------------
----------------
#!/bin/sh
#
# /root/sbin/get_ddns_addr
#
source /etc/sysconfig/config
nslookup -sil $WAN_HOST | grep -A 1 $WAN_HOST | awk '{print $4}' RS="/"
----------------
|