views:

23

answers:

2

On a Ubuntu 10.04 Server I would like to do the following with a bash script:

Create a service that monitors the ISDN connection and if downtime exceeds 60 seconds forces reconnect. My current solution looks something like this:

#!/usr/bin/bash
LOGFILE=/home/msw/router/ping-stats.txt
TIME="`date +%C%y%m%d%H%M`"
/sbin/ping -c 1 google.com > /dev/null 2>&1
if [ "$?" == "0" ]
then
        STATUS=1
else
        STATUS=0
fi
echo "$TIME $STATUS" >> $LOGFILE

Since bandwidth is precious on an ISDN connection, I would like to avoid the ping and replace it with a command that simply checks for the status of the network device. Is it possible to infer from that if the connection is "up"?

I would also like to implement the solution as a service that checks connectivity continually instead of checking periodically with a cronjob.

I would really appreciate it if somebody could push me in the right direction.

Thank you

+1  A: 

For quick-and-dirty there's nm-tool. dbus-send can be a bit more precise, but needs knowledge of how D-Bus works with NetworkManager. If you want something persistent then you'll need to learn how to interact with D-Bus, but that may require using something a bit lower-level such as Python.

Ignacio Vazquez-Abrams
Interesting. I will look into that, thank you very much.
nickname47
+1  A: 

Is your ISDN provided by an internal adapter or via an Ethernet connection? If you have an external "modem" you'd need to query that using SNMP or its proprietary facility.

You can do your test this way, by the way:

if /sbin/ping -c 1 google.com > /dev/null 2>&1
then
    ...

Also, a single ping is a very small number of bytes. If you're only doing it a few times a minute you may never notice it.

Dennis Williamson
Thank you very much. The ISDN is provided by an internal Fritz!Card.
nickname47