Mailinglist Archive: opensuse (1540 mails)

< Previous Next >
Re: [opensuse] Script to check interface & restart network service
On 02/14/2010 08:30 PM, Wong wrote:
> I tried to put the script file into ~/init.d/after.local either
at > the top or the bottom of after.local. All daemons became
unloaded to > system including iptables script.

That's impossible, one script can not unload the rest. You must be
doing
something else.

Hi Carlos,

Perhaps my knowledge limitation cannot explain it why, but it is
truly happen. It is a mystery for me.

It is rather a language barrier, I'm afraid.

To avoid misunderstanding, the others were not loaded then unloaded.
But it was not started by after.local if I put the script or loaded
from external file.

I wish I could have the script and put in to a file and loaded by
after.local. It will be more organized.

Now that I think, that code can not be written into after.local, or
the system will "think" that the init scripts failed. All those
scripts must exit sucessfully, you can not leave one working in a
loop. Yo have to call another script in background from after.local
and exit.

I would create a new service to load just after "/etc/init.d/network",
kind of "networkwatchdog" which would in turn start/kill another
script running the loop.


Thousand thanks Carlos, David, and others.

It will be a great stuff that a must have for users that using ADSL link.

Best Regards,

Wong

Wong,

I still needed to see your 'ifconfig' output, but here is the script
cleaned up
a bit. You can use it as discussed, but you should check whether the link
is up
by some other manner than pinging a public server (it works though ;-)

You will notice that in this version of the script, I moved the test of
dsl0 to
a separate function 'dsl0test()' so all you need to do is edit the
function when
you decide on the test you want to use. You can also specify the wait
period
from the command line (default is 60 seconds). So if you wanted to change
the
interval to 20 seconds, all you need to do is start the script with:

nameofscript 20

David and Carlos can fill in my screwups, but it should work well for you.
Have
fun.


#!/bin/bash

# check for root and use sudo if not root
[[ $UID -eq 0 ]] && prefix="" || prefix="sudo "

runfile=/var/run/chkdsl0.run
tmpfile=/tmp/chkdsl0
ckinterval=${1:-60}

cleanup() {
${prefix}rm -f $runfile
}

trap cleanup SIGINT SIGTERM EXIT

## Change this test based on your 'ifconfig' output (this is temporary)
dsl0test() {
ping -q -c1 yahoo.com &>/dev/null
return $?
}

## if the runfile is still present check the PID to see if it is running
[[ -f $runfile ]] && {
ps ax | grep -q $(<$runfile) &>/dev/null
PIDrunning=$?
}

## if not already running, start checking dsl0 connection
if [[ ! -f $runfile ]] || [[ $PIDrunning != 0 ]]; then
echo "$$" > $tmpfile && ${prefix}cp $tmpfile $runfile && rm $tmpfile
## keep runing until killed or $runfile deleted
while [[ -f $runfile ]] && [[ $$ == $( <$runfile ) ]]; do
## if still OK, sleep for $ckinterval seconds, if dls0 down restart
network
if dsl0test; then
sleep $ckinterval
else
${prefix}rcnetwork restart
fi
done
fi

exit 0

Dave, here it is;

dsl0 Link encap:Point-to-Point Protocol
inet addr:w.x.y.z P-t-P:a.b.c.d Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
RX packets:132535 errors:0 dropped:0 overruns:0 frame:0
TX packets:122361 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:126349004 (120.4 Mb) TX bytes:18393814 (17.5 Mb)

eth0 Link encap:Ethernet HWaddr 00:60:93:23:E2:49
inet addr:192.168.0.2 Bcast:192.168.0.3 Mask:255.255.255.252
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:134283 errors:0 dropped:0 overruns:0 frame:0
TX packets:124110 errors:0 dropped:0 overruns:0 carrier:0
collisions:232 txqueuelen:1000
RX bytes:129382957 (123.3 Mb) TX bytes:21190789 (20.2 Mb)
Interrupt:20 Base address:0xd000

eth1 Link encap:Ethernet HWaddr 00:1D:C0:A3:2A:95
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:97434 errors:0 dropped:0 overruns:0 frame:0
TX packets:129258 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:20350028 (19.4 Mb) TX bytes:130289597 (124.2 Mb)
Memory:e0700000-e0720000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2115 errors:0 dropped:0 overruns:0 frame:0
TX packets:2115 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:223533 (218.2 Kb) TX bytes:223533 (218.2 Kb)

I know that I should ping my provider router (a.b.c.d) instead yahoo.com and put the addr into script.

Is the script to be run from external file or put into after.local? Please
advise me which is better.

Thanks a lot!

Wong


--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >