Bash script to monitor ISDN connection

510 views Asked by At

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

2

There are 2 answers

0
Ignacio Vazquez-Abrams On BEST ANSWER

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.

1
Dennis Williamson On

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.