RE: bash script fails in squeeze

2011-07-07 Thread Bonno Bloksma
Hi,


Bonno Bloksma:
 
 This bash script has been doing it's job for the past few years but 
 suddenly stopped working in squeeze. Each part seems to work but the 
 complete script does not. :-(

I must admit that I am not really inclined to try to understand what your
scripts should do and and why they do what they do instead. But one
advice: debugging shell scripts is made *a lot* easier when using 'set -x'
in the script.

Although that set -x did give more information it did not help. However,
someone else determined that the old script had an undefined exit value
which turned out to be a negative value which was then interpreted as being
exit 1, or something like that.
Anyway, a simple exit 0 at the end of the script solved it. :-)

Bonno Bloksma
senior systeembeheerder



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/007601cc3cb0$c5852610$508f7230$@blok...@tio.nl



Re: bash script fails in squeeze

2011-07-06 Thread Jochen Schulz
Bonno Bloksma:
 
 This bash script has been doing it's job for the past few years but
 suddenly stopped working in squeeze. Each part seems to work but the
 complete script does not. :-(

I must admit that I am not really inclined to try to understand what
your scripts should do and and why they do what they do instead. But one
advice: debugging shell scripts is made *a lot* easier when using 'set
-x' in the script.

J.
-- 
I am not scared of death but terrified of people in Tommy Hilfiger
sweatshirts.
[Agree]   [Disagree]
 http://www.slowlydownward.com/NODATA/data_enter2.html


signature.asc
Description: Digital signature


Re: bash script fails in squeeze

2011-07-06 Thread lee
Bonno Bloksma b.blok...@tio.nl writes:

 Below the full defaultgw-test.sh script which attempts to determin
 whethet the local internet gateway (ADLS, Cable, etc) is
 functioning. If not it will switch the default gateway over to the
 intranet connection where the internet traffic when then leave our WAN
 network. This way each site has a fast local consumer internet gateway
 but still has the reliability of a buisiness connection.

Would load balancing be an option for you?  With load balancing and
traffic shaping, you might be able to get much better results.


-- 
html messages are obsolete


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/87zkkrxm9n@yun.yagibdah.de



Re: bash script fails in squeeze

2011-07-06 Thread Javier Barroso
On Wed, Jul 6, 2011 at 4:33 PM, Bonno Bloksma b.blok...@tio.nl wrote:
 Hi,

 This script has been working flawlesly in Debian Etch and Lenny but after
 upgrading to Squeeze it no longer seems to work and I cannot find out why.

 Below the full defaultgw-test.sh script which attempts to determin whethet
 the local internet gateway (ADLS, Cable, etc) is functioning. If not it will
 switch the default gateway over to the intranet connection where the
 internet traffic when then leave our WAN network. This way each site has a
 fast local consumer internet gateway but still has the reliability of a
 buisiness connection.

 This bash script has been doing it's job for the past few years but suddenly
 stopped working in squeeze. Each part seems to work but the complete script
 does not. :-(
 I have been doing some test runs to see where the problem is and I cannot
 find it. I hope someone can shed some light on this weird problem.

 In the /etc/tiofirewall.conf file is a line
 UPLINK_IP=192.168.178.1
 which the script reads to determine what the default gateway for that site
 is supposed to be.

 --defaultgw-test.sh-
 #!/bin/bash

 # v1.2
 # 12-jul-2010
 # 1.0 PINGHOST2 nu ook goed toegevoegd voor test defaultgw in de lucht
 # pingtest() nu met count 2
 # 1.1 ADSL_IP heet nu UPLINK_IP (change firewall 3.43)
 # Debug info toegevoegd
 # 1.2 IP nummer fw.tio.nl gewijzigd

 DEBUGINFO=false
 # PINGHOST is ping.xs4all.nl, de maatstaf of de DSL het nog doet
 PINGHOST=194.109.21.51
 # PINGHOST2 is ip van fw.tio.nl voor het geval de eerste even niet
 bereikbaar is
 PINGHOST2=77.222.72.50
 # DEFAULTGW moet de defaultgateway van deze machine zijn
 DEFAULTGW=`grep UPLINK_IP= /etc/tiofirewall.conf | cut -d= -f2`

 if [ $DEBUGINFO = true ] ; then
  echo Default gateway is $DEFAULTGW
 fi

 # hieronder hoeft niets gewijzigd te worden

 function pingtest() {
  IPHOST=$1
  ping -c2 $IPHOST /dev/null 21
  VALUE=$?
  [ $VALUE == 0 ]  echo OK || echo NOK
 }

 function routezebra() {
  [ X`ip route ls | grep ^default | grep zebra` == X ]  \
   echo NO || echo YES
 }

 function nodefaultgw() {
  [ `routezebra` == NO ]  \
   echo deleting default route via DSL, now learning default via OSPF!  \
   ip route del default
 }

 function yesdefaultgw() {
  [ `routezebra` == YES ]  \
   echo adding default route via DSL, ignoring default learnt via OSPF  \
   ip route add default via $DEFAULTGW
 }

 # test of $PINGHOST pingt
 # pingt hij niet, test dan nog een keer
 # pingt hij dan nog niet, verwijder dan de defaultroute
 [ `pingtest $PINGHOST` == NOK ]  \
 [ `pingtest $PINGHOST2` == NOK ]  \
  sleep 2  \
  [ `pingtest $PINGHOST` == NOK ]  \
  [ `pingtest $PINGHOST2` == NOK ]  \
  nodefaultgw

 sleep 2

 # test of $PINGHOST pingt
 # pingt hij, test dan nog een keer
 # pingt hij dan weer, voeg dan de defaultroute toe
 ([ `pingtest $PINGHOST` == OK ] || [ `pingtest $PINGHOST2` == OK ])  \
  sleep 2  \
  ([ `pingtest $PINGHOST` == OK ] || [ `pingtest $PINGHOST2` == OK ])  \
  yesdefaultgw
 --\defaultgw-test.sh-


 Below some tests.
 --callscript.sh-
 echo pingonly.sh --
 /root/test/pingonly.sh
 echo status=$?

 echo ping2.sh --
 /root/test/ping2.sh
 echo status=$?

 echo ping3.sh --
 /root/test/ping3.sh
 echo status=$?

 echo ping4.sh --
 /root/test/ping4.sh
 echo status=$?

 echo no-yes-defaultgw.sh --
 /root/test/no-yes-defaultgw.sh
 echo status=$?
 --\callscript.sh-

 OUTPUT callscript
 =
 linrtm:~/test# ./callscript.sh
 pingonly.sh --
 OK
 OK
 status=0
 ping2.sh --
 default gateway
 status=0
 ping3.sh --
 default gateway
 status=0
 ping4.sh --
 status=1
 no-yes-defaultgw.sh --
 deleting default route via DSL, now learning default via OSPF!
 adding default route via DSL, ignoring default learnt via OSPF
 status=0

 SCRIPT INHOUD
 =

 All scripts contain the same content as the defaultgw-test.sh script with
 the same procedures and definitions. Only the action lines at the end of
 the script are different.

 pingonly.sh --
 pingtest $PINGHOST
 pingtest $PINGHOST2

 ping2.sh --
 # test of $PINGHOST pingt
 # pingt hij niet, test dan nog een keer
 # pingt hij dan nog niet, verwijder dan de defaultroute
 [ `pingtest $PINGHOST` == NOK ]  \
 [ `pingtest $PINGHOST2` == NOK ]  \
  echo no default gateway || echo default gateway

 ping3.sh --
 # test of $PINGHOST pingt
 # pingt hij niet, test dan nog een keer
 # pingt hij dan nog niet, verwijder dan de defaultroute
 [ `pingtest $PINGHOST` == NOK ]  \
 [ `pingtest $PINGHOST2` == NOK ]  \
  sleep 2  \
  [ `pingtest $PINGHOST` == NOK ]  \
  [ `pingtest $PINGHOST2` == NOK ]  \
  echo no default gateway || echo default gateway

 ping4.sh --
 # test of $PINGHOST pingt
 # pingt hij niet, test dan nog een keer
 # pingt hij dan nog 

Re: bash script fails in squeeze

2011-07-06 Thread Cam Hutchison
Bonno Bloksma b.blok...@tio.nl writes:

[...snip...]
ping3.sh --
default gateway
status=0
ping4.sh --
status=1

[...snip...]

ping3.sh --
# test of $PINGHOST pingt
# pingt hij niet, test dan nog een keer
# pingt hij dan nog niet, verwijder dan de defaultroute
[ `pingtest $PINGHOST` == NOK ]  \
[ `pingtest $PINGHOST2` == NOK ]  \
  sleep 2  \
  [ `pingtest $PINGHOST` == NOK ]  \
  [ `pingtest $PINGHOST2` == NOK ]  \
   echo no default gateway || echo default gateway

ping4.sh --
# test of $PINGHOST pingt
# pingt hij niet, test dan nog een keer
# pingt hij dan nog niet, verwijder dan de defaultroute
[ `pingtest $PINGHOST` == NOK ]  \
[ `pingtest $PINGHOST2` == NOK ]  \
  sleep 2  \
  [ `pingtest $PINGHOST` == NOK ]  \
  [ `pingtest $PINGHOST2` == NOK ]  \
  nodefaultgw

[...snip...]

I hope someone can find a reason why for instance ping4 fails and ping3 does 
not.

ping3 does not fail because you have '|| echo default gateway' on the
end, and this is the branch that is being taken. echo(1) returns true so
you get a status of zero from the whole list.

ping4 does not have an '|| cmd' branch, so the whole list retuns false
(non-zero).

These results are consistent with one of the pingtest commands returning
OK (or not returning NOK, technically)

I think you are looking in the wrong place.



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/76a9.4e1523de.e4...@getafix.xdna.net