Mailinglist Archive: opensuse (1540 mails)

< Previous Next >
Re: [opensuse] Script to check interface & restart network service
  • From: David Haller <dnh@xxxxxxxxxxxx>
  • Date: Thu, 11 Feb 2010 04:37:18 +0100
  • Message-id: <20100211033718.GA12896@xxxxxxxxxxxxxxxxxx>
Hello,

On Wed, 10 Feb 2010, David C. Rankin wrote:
On 02/10/2010 01:22 AM, Wong wrote:
[..]
#!/bin/bash
runfile=/tmp/chkdsl0.run

Bad. Use /var/run/

cleanup() {
rm $runfile
}

Should be:

rm -f "$runfile"

trap cleanup trap cleanup SIGINT SIGTERM EXIT

if [[ ! -f $runfile ]]; then

A simple:

if ! test -f "$runfile"; then

suffices and doesn't need bash.

touch $runfile

Should be:

echo "$$" > "$runfile"

while :; do
if ! ping -q -c1 yahoo.com &>/dev/null; then

You can also check for the interface (with ifconfig or ip link show),
or ping the router, if you use one. I don't think yahoo'll like it to
be pinged every 60 seconds.

ifconfig:

dev=dsl0

if LC_ALL=C /sbin/ifconfig "$dev" | grep -q 'UP.*MTU'; then
## interface is up
else

rcnetwork restart # (as root, or 'sudo rcnetwork restart' with sudo)
fi
sleep 60
done
fi

I can't look up or remember the 'ip' syntax (different system).

call it say 'chkdsl0.sh' and put it in say ~/Documents. Make it
executable with chmod +x chkdsl0.sh. Then just call it and
background it in your
~./bashrc with the following statement:

~/Documents/chkdsl10.sh &

That's what ~/bin/ is for! Such a script is definitely not a document.

and your will then execute a ping check against yahoo once every 60
seconds and if yahoo.com doesn't respond then you restart the network
to regain dsl0. There are a lot of different ways to do this and this
is just a very basic solution with a reasonable check to prevent
duplicate check process with each start of a new shell that you can
expand on. Good luck.

Start it in ~/.profile.

But actually, I'd do the check in/from whatever actually needs the
connection. Wong, could you elaborate on why you need to check the
connection?

HTH,
-dnh

--
So Linus, what are we doing tonight?
The same thing we do every night Tux. Try to take over the world!
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References