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
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.