shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Erro ao executar um script


From: Edilson Luiz dos Santos - DTI
Subject: Erro ao executar um script
Date: Wed, 8 Jan 2003 19:10:26 -0300

Ao executar este script, recebo a mensagem de bad interpreter: no such file
or directory

o script tem todas as permissões e o bash está no /bin   estou aprendendo a
programar em shell e estou com este problema

grato



#!/bin/bash

# author: Jesse Burkhardt
# date:   2002/07/09

# This shell script functions as a daemon to switch ip gateways
# when the primary one loses connectivity. The failover is initiated
# when by means of dead gateway detection (DTD) kludge - not kernel 
# based. Once the dead gateway is redetected as being alive primary 
# gateway (GW) will be restored.

# Installation: This script should be invoked from the local startup
# script, /etc/rc.local. Appended to this script should be the line:
# '/root/scripts/gw_failover.sh &', insuring that this will start on
# boot.

# N.B. - Important testing note: Unplugging the eth0 cable is only a
# partial test, simulating the ISP being down. Turning off the router
# simulates both the router and the ISP being down. 

# Testing note: GW_1 is a router LAN interface; when it cannot be 
# reached the router is down. NEXTHOP_1 is the first IP reached at
# ISP; when it cannot be reached the ISP is down. (Get the NEXTHOP 
# value by doing a traceroute to the router's gateway interface 
# originating the trace from a connection other than the ISP's.)

# Logic matrix:

#       +---------+-----------+-----------+----------------+
#       ! current ! GW_1/NH_1 ! GW_2/NH_2 ! Action         !
#       +---------+-----------+-----------+----------------+
#     1 !   GW_1  !     up    !     up    ! nothing        !
#       +---------+-----------+-----------+----------------+
#     2 !   GW_1  !    down   !    down   ! nothing        !
#       +---------+-----------+-----------+----------------+
#     3 !   GW_1  !    down   !     up    ! switch to GW_2 !
#       +---------+-----------+-----------+----------------+
#     4 !   GW_2  !     up    !     up    ! switch to GW_1 !
#       +---------+-----------+-----------+----------------+
#     5 !   GW_2  !    down   !    down   ! nothing        !
#       +---------+-----------+-----------+----------------+
#     6 !   GW_2  !    down   !     up    ! switch to GW_1 !
#       +---------+-----------+-----------+----------------+

#        * GW_1/NH_1 'up' means that BOTH IPs are reachable.
#          GW_1/NH_1 'down' means that EITHER IP is unreachable.

# Set our IP numbers as variables to help generalize this script
# (GW is for GateWay and NH is for NextHop):

# ISP_1 (Sprint):

GW_1=192.168.0.1
NH_1=192.168.0.2
DEV_1=eth1

# ISP_2 (Galaxy):

GW_2=192.168.1.1
NH_2=192.168.1.2
DEV_2=eth2

# log strings:

LOG_STR_1='gw_failover: Switching default GW to 192.168.1.1 - ifdown eth1'
LOG_STR_2='gw_failover: Switching default GW to 192.168.0.1 - ifup eth1'

# mail strings:

MAIL_TO='address@hidden address@hidden'
MAIL_SUBJECT_1='Sprint 192.168.0.1/0 is down'
MAIL_SUBJECT_2='Sprint 192.168.0.0/0 is back up'
MAIL_BODY_1=$LOG_STR_1
MAIL_BODY_2=$LOG_STR_2

# Need to initialize all interfaces and default GW if not already 
# done. This is to force a GW failure if necessary to fall into the
# interface failover logic in the while loop.

service network restart

while [ 1 = 1 ]; do

    # Collect all matrix values.

    ping -c 1 $GW_1 | grep "100% packet loss"
    GW_PINGERROR_1=$?
    echo GW_PINGERROR_1 = $GW_PINGERROR_1

    ping -c 1 $NH_1 | grep "100% packet loss"
    NH_PINGERROR_1=$?
    echo NH_PINGERROR_1 = $NH_PINGERROR_1

    if [ $GW_PINGERROR_1 || $NH_PINGERROR_1 ];
    then
        PINGERROR_1 = 0
    else
        PINGERROR_1 = 1
    fi
    echo PINGERROR_1 = $PINGERROR_1

    ping -c 1 $GW_2 | grep "100% packet loss"
    GW_PINGERROR_2=$?
    echo GW_PINGERROR_2 = $GW_PINGERROR_2

    ping -c 1 $NH_2 | grep "100% packet loss"
    NH_PINGERROR_2=$?
    echo NH_PINGERROR_2 = $NH_PINGERROR_2

    if [ $GW_PINGERROR_2 || $NH_PINGERROR_2 ];
    then
        PINGERROR_2 = 0
    else
        PINGERROR_2 = 1
    fi
    echo PINGERROR_2 = $PINGERROR_2

    # Read as: "If both ISPs are not up or both ISPs are not both down ... 
    # then look at switching GWs"

    if ! [ [ $PINGERROR_1 && $PINGERROR_2 ] || [ ! $PINGERROR_1 && !
$PINGERROR_2 ] ];
    then

        echo --> Primary ISP failure condition

        ip route list dev $DEV_2 | grep "default via $GW_2"
        GW_STATUS_2=$?
        echo
        echo GW_STATUS_2 = $GW_STATUS_2
        echo 
        # Don't change GW if it already has been.

        if [ $GW_STATUS_2 != 0 ];
        then
            echo $MAIL_BODY_1 | mail -s $MAIL_SUBJECT_1 $MAIL_TO
            echo
            echo `date`: $LOG_STR_1 >> /var/log/messages
            ip route replace default nexthop via $GW_2 dev $DEV_2
            ifdown $DEV_1
        fi

    else

        ip route list dev eth0 | grep "default via $GW_1"
        GW_STATUS_2=$?
        echo
        echo GW_STATUS_2 = $GW_STATUS_2
        # Don't change GW if it already has been.

        if [ $GW_STATUS_2 != 0 ];
        then
            echo $MAIL_BODY_2 | mail -s  $MAIL_SUBJECT_2 $MAIL_TO
            echo
            echo `date`: $LOG_STR_2 >> /var/log/messages
            ifup $DEV_1
            ip route replace default nexthop via $GW_1 dev $DEV_1

        fi

    fi

    sleep 5

done





Edilson Luiz dos Santos
Estok  Comércio e Representações Ltda.
DTI - Network Departament
Gennari & Peartree Projetos e Sistemas S/C Ltda.
Núcleo de Suporte Técnico e Gestão de Produção
mailto:address@hidden
Fone 1: (11) 4196-8647
Fone 2: (11) 4196-8645
Móvel  : (11) 9803-2573



reply via email to

[Prev in Thread] Current Thread [Next in Thread]