pingscript to deal with flakey connections

Remco Barendse mailscanner at barendse.to
Tue Nov 21 08:35:52 GMT 2006


Hi list!

I have several MailScanner boxes sending/receiving e-mail and forwarding 
it to my M$ Exchange box. The boxes are connected to different DSL 
connections whose connections tends to be flakey. I want to prevent that 
Exchange thinks a MS box is still up and running and sending outgoing mail 
to it when the connection is down and MS is only queuing up the mail, not 
sending it.

I am trying to modify a ping script i found somewhere, basically I want it 
to stop MS to accept connections when the DSL line is down.

The script doesn't seem to be giving me expected results though (probably 
because I do not have any programming skills at all), maybe somebody 
already has a similar ping script? If yes, could it be posted, or maybe 
someone can help me on what I've got so far?

I think such a script could be usefull for others on this list too.

This is my feeble attempt to modify an other script I found :
http://www.ecem-it.nl/pingscript/pingscript.txt

the contents is also below:



#!/bin/sh
# Initialisation

date=`date +'%b %d %k:%M:%S'`
logfile="/var/log/connection.log"

ping1="ping -c 2 -i 2 www.xs4all.nl";
ping2="ping -c 2 -i 2 www.planet.nl";
ping3="ping -c 2 -i 2 www.redhat.com";
ping4="ping -c 2 -i 2 www.ti.com";
ping5="ping -c 2 -i 2 www.oracle.com";

echo "" >> $logfile
echo $date "Checking if connection is still up ..."  >> $logfile

if ! $ping1 > /dev/null & ! $ping2 > /dev/null & ! $ping3 > /dev/null & ! 
$ping4 > /dev/null & ! $ping5 > /dev/null;
then
    if [ -f /tmp/conndown ] ; then
       echo $date "No ping packets received, connection is still down"  | 
tee -a $logfile
    else
    /sbin/clock >> /tmp/conndown
    echo $date "No ping packets received"  | tee -a $logfile
    echo $date "Connection is down! ===> stopping MailScanner ..."  | tee 
-a $logfile
    service MailScanner stop
    exit 1
    fi
else
    echo -n 
"-----------------------------------------------------------------------------------------" 
> /dev/null
    echo -n "PINGRESULTS:"                                                              
> /dev/null
    echo -n 
"-----------------------------------------------------------------------------------------" 
> /dev/null
    ping -c 1 www.xs4all.nl                                                             
> /dev/null
    echo -n 
"-----------------------------------------------------------------------------------------" 
> /dev/null
    ping -c 1 www.planet.nl                                                             
> /dev/null
    echo -n 
"-----------------------------------------------------------------------------------------" 
> /dev/null
    ping -c 1 www.redhat.nl                                                             
> /dev/null
    echo -n 
"-----------------------------------------------------------------------------------------" 
> /dev/null
    ping -c 1 www.ti.com                                                                
> /dev/null
    echo -n 
"-----------------------------------------------------------------------------------------" 
> /dev/null
    ping -c 1 www.oracle.com                                                            
> /dev/null
    echo -n 
"-----------------------------------------------------------------------------------------" 
> /dev/null
    if [ -f /tmp/conndown ] ; then
    echo $date "Connection is up! Restarting MailScanner ..."  | tee -a 
$logfile
    rm -f /tmp/conndown
    service MailScanner start
    else
    echo $date "Connection is still up!"  >> $logfile
    exit 1
    fi
fi



More information about the MailScanner mailing list