Проверка статуса соединения из с

Post new topic   Reply to topic    DD-WRT Forum Index -> Оборудование на основе Broadcom
Author Message
AndreyAv
DD-WRT Novice


Joined: 20 Dec 2010
Posts: 17

PostPosted: Wed Dec 22, 2010 5:36    Post subject: Проверка статуса соединения из с Reply with quote
Роутер DIR-320, прошивка Eko Mini USB FTP из последних.

Проверяю доступность интернета и сети:
ping -c 1 узел.в.интернете | grep packets
ping -c 1 шлюз.в.сети | grep packets

соответственно например:
set -- $(ping -c 1 ya.ru | grep packets)
load="${1}"
после этого в $load будет или строка о том что пакет успешно вернулся, или пусто.
Вопрос в том как это правильно проверить?
Экспериментировать сложно, потому что маршрутизатор через какое-то количество экспериментов в веб интерфейсе перестает выдавать ответы.
Как то так? if [ "$load" == "" ] то узел недоступен?
Sponsor
AndreyAv
DD-WRT Novice


Joined: 20 Dec 2010
Posts: 17

PostPosted: Wed Dec 22, 2010 15:25    Post subject: Reply with quote
Разобрался. Если кому интересно вот скрипт:

Code:
# Constants
ADDR_GATE=10.1.1.1
ADDR_INET=ya.ru
PERIOD_GENERIC=60
PERIOD_ALERT=10
# Loop
period=$PERIOD_ALERT
status=0
count=0
while sleep 1
do
  if [ $count -ge $period ]
  then
    inet=$(ping -c 1 $ADDR_INET | grep packets)
    if [ "$inet" == "" ]
    then
      gate=$(ping -c 1 $ADDR_GATE | grep packets)
      if [ "$gate" == "" ]
      then
        # Red
        status=3
      else
        # Blue
        status=4
      fi
      period=$PERIOD_ALERT
    else
      # None
      status=0
      period=$PERIOD_GENERIC
    fi
    count=0
  fi
  # LED
  if [ $status -gt 0 ]
  then
    i=0
    while [ $i -lt 3 ]
    do
      gpio disable $status
      usleep 1000
      gpio enable $status
      usleep 50000
      i=`expr $i + 1`
    done
  fi
  count=`expr $count + 1`
done
loginrl103
DD-WRT User


Joined: 06 Nov 2009
Posts: 389

PostPosted: Thu Dec 23, 2010 11:36    Post subject: Reply with quote
пляски с
grep packets...
if [ "$gate" == "" ]...

можно заменить на if [ $? != 0 ]...
AndreyAv
DD-WRT Novice


Joined: 20 Dec 2010
Posts: 17

PostPosted: Thu Dec 23, 2010 16:10    Post subject: Reply with quote
Спасибо.
Вторая версия - при нажатии на кнопку передергивается WAN-интерфейс:

Code:
# Constants
INTERFACE=vlan1
ADDR_GATE=10.2.2.1
ADDR_INET=ya.ru
PERIOD_GENERIC=60
PERIOD_ALERT=5
# Red
color=3
gpio disable $color
# Loop
period=$PERIOD_ALERT
count=0
while sleep 1
do
  # Button
  if [ $(($(printf "%d" "'`dd if=/dev/gpio/in count=1 2>/dev/null`")&64)) -eq 0 ]
  then
    if [ $color -ne 0 ]
    then
      gpio enable $color
    fi
    ifconfig $INTERFACE down
    # Red
    color=3
    i=0
    while [ $i -lt 30 ]
    do
      gpio disable $color
      usleep 50000
      gpio enable $color
      usleep 50000
      i=`expr $i + 1`
    done
    ifconfig $INTERFACE up
    gpio disable $color
    count=$period
  fi
  # Test
  if [ $count -ge $period ]
  then
    if ! ping -c 1 $ADDR_INET >/dev/null
    then
      if ! ping -c 1 $ADDR_GATE >/dev/null
      then
        # Red
        if [ $color -ne 3 ]
        then
          gpio enable $color
          color=3
          gpio disable $color
        fi
      else
        # Blue
        if [ $color -ne 4 ]
        then
          gpio enable $color
          color=4
          gpio disable $color
        fi
      fi
      period=$PERIOD_ALERT
    else
      # None
      if [ $color -ne 0 ]
      then
        gpio enable $color
        color=0
      fi
      period=$PERIOD_GENERIC
    fi
    count=0
  fi
  count=`expr $count + 1`
done
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Оборудование на основе Broadcom All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum