script 1
root@timekeeper:~# cat arec.sh
#!/bin/sh
while [ 1==1 ] ; do
ping=0
for n in `awk '/nameserver/{print $2}' /etc/resolv.conf | xargs` ; do
if ping -c 1 $n > /dev/null ; then
ping=1
fi
done
if ! [ $ping == "1" ] ; then
logger ADSL connection restarted
/etc/init.d/dial start
#killall pppd
#ifconfig nas0 0
#killall br2684ctl
#/etc/init.d/dial start
fi
sleep 60
done
root@timekeeper:~#
script 2
root@timekeeper:~# cat autorecon.sh
#!/bin/bash
SLEEP=60
GATEWAY=$(ip addr show dev ppp0 | \
sed -n 3p | \
awk '{ print $4 }' | \
sed -e 's:/[0-9]*::' \
)
#TIMER=/var/run/autorecon.timer
TIMER=/tmp/autorecon.timer # for non-root tests
PASS=0
do_dnsstuff()
{
# Whatever ;)
echo "DNS stuff..."
}
do_pass()
{
((PASS++))
echo $(($(date +%s)+($SLEEP*2+5))) > $TIMER
echo $PASS >> $TIMER
take_action
}
take_action()
{
# Here are the reconnect attemps number and actions to take.
case $PASS in
2|4|5|6) echo /etc/init.d/dial restart;;
3) echo /etc/init.d/natfire restart;;
7) echo reboot;;
esac
exit -$PASS
}
if [ -e $TIMER ]; then
if [ $(date +%s) -lt $(sed -n "1p" $TIMER) ]; then
PASS=$(sed -n "2p" $TIMER)
rm $TIMER
else
rm $TIMER
fi
fi
# See if the ATM bridge or pppd died.
if [ -z $(pidof pppd) ] || [ -z $(pidof br2684ctl) ]; then
echo "pppd or ATM bridge died."
do_pass
fi
# See if ppp0 exist in the links.
if [ -z $GATEWAY ]; then
echo "ppp0 does not exist."
do_pass
fi
# If ping fails, take actions.
ping -c 3 $GATEWAY > /dev/null || do_pass
echo "Ping OK"
# If DNS fails, take actions for DNS.
host google.com > /dev/null || do_dnsstuff
echo "DNS OK"
exit 0
root@timekeeper:~#
script 3
root@timekeeper:~# cat check_host.sh
#!/bin/sh
# check_host.sh
# SETEAZA variabilele de mai jos
##################################################
# fis. in care vor fi logate intreruperile
LOG_FILE=/var/log/check_host
# daca exista fis. $LOCK_FILE o alta instanta a scriptului inca ruleaza
LOCK_FILE=/tmp/check_host.sh.lock
# daca exista fis. $TAG_FILE inseamna ca si testul anterior a esuat sa
# stabileasca conexiunea
TAG_FILE=/tmp/chech_host.sh.tag
# hostul fol. pentru verificarea conexiunii; poate fi gateway-ul, de ex.
HOST=www.yahoo.com
# numele fis. care contine setarile pentru conexiunea ADSL
# acest fis. se afla deobicei in dir. /etc/ppp/peers/
CONEXIUNE=speedtch
if ! ping -c 3 $HOST &>/dev/null && ! test -f $LOCK_FILE ; then
touch $LOCK_FILE
# aici incercam sa restabilim conexiunea
killall -9 pppd
sleep 35
pppd call $CONEXIUNE
ping -c 3 $HOST &>/dev/null
TEST=$?
if [ $TEST -eq 0 ]; then
if [ ! -f $TAG_FILE ]; then
echo "SINGLE >" `date`>>$LOG_FILE
else
echo "END >" `date`>>$LOG_FILE
rm -f $TAG_FILE
fi
else
if [ ! -f $TAG_FILE ]; then
echo "BEGINING >" `date`>>$LOG_FILE
touch $TAG_FILE
fi
fi
rm -f $LOCK_FILE
fi
root@timekeeper:~#
script 4
root@timekeeper:~# cat try.sh
#!/bin/sh
if ! ping -c 1 -n 193.231.100.2 > /dev/null ; then /etc/init.d/dial start ; logger ADSL connection restarted ; fi
root@timekeeper:~#