#!/bin/sh # # exec from cron by root # PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin export PATH # # 2重起動抑止の為のロック取得 # mkdir /tmp/dhcpcd_check.sh.LOCK || exit 1 # basedir=~m-ito/provider/catv # device=eth0 server=www.catv.ne.jp #------------------------------------------------------------------------------------ result=`ping -c 1 ${server} 2>&1 | grep " 0% packet loss"` # # インターネット側にPING不通の場合dhcpcdを再起動 # if [ "X${result}" = "X" ] then echo -n "dhcpcd_check : restart dhcpcd : " >>/tmp/dhcpcd_check.log date >>/tmp/dhcpcd_check.log kill -TERM `cat /var/run/dhcpcd-${device}.pid` sleep 2 # # option : -R は dhcpcd による /erc/resolv.conf の書き換えを # 抑止する。自前で BIND を立てる都合上このようにした。 # -d for debugging into /var/log/dhcpcd.log # /usr/local/sbin/dhcpcd -R ${device} >/dev/null 2>&1 fi # result=`ping -c 1 ${server} 2>&1 | grep " 0% packet loss"` # # dhcpcdがIP取得失敗した場合、前回の取得情報で強制的にeth0を設定 # if [ "X${result}" = "X" ] then echo -n "dhcpcd_check : force recover : " >>/tmp/dhcpcd_check.log date >>/tmp/dhcpcd_check.log sleep 2 ${basedir}/etc/dhcp_force_recover.sh >/dev/null 2>&1 fi # # 2重起動抑止の為のロック開放 # rmdir /tmp/dhcpcd_check.sh.LOCK