diff --git a/check_net.conf.sample b/check_net.conf.sample index 4ce23af..99fd11a 100644 --- a/check_net.conf.sample +++ b/check_net.conf.sample @@ -11,6 +11,11 @@ netconfig_script=/usr/local/sbin/netconfig.sh log_file=/var/log/check_net.log +# - If no inet device is online at startup, no ping address can be determined and further on +# - no online test is possible. So use this ip-address as backup ping address. +# - +BACKUP_PING_ADDR="8.8.8.8" + # - Put in your DSL devices (refers to your network configuration) # - youe wish be congigured by that script diff --git a/check_net.sh b/check_net.sh index 0ee4573..3d56f20 100755 --- a/check_net.sh +++ b/check_net.sh @@ -60,10 +60,19 @@ set_ping_addresses () { if [ ${#ping_ip_arr[@]} -lt 1 ]; then echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Setting IP-Address(es) for ping test FAILED!" >> $log_file + if [[ ${#previous_ping_ip_arr[@]} -gt 0 ]] ; then + ping_ip_arr=("${previous_ping_ip_arr[@]}") + echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] Take IP-Address(es) from previous ping test:" >> $log_file + echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] ${ping_ip_arr[@]}" >> $log_file + else + ping_ip_arr+=("$BACKUP_PING_ADDR") + fi else if $DEBUG ; then echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] IP-Addresses for ping tests set to ${ping_ip_arr[@]}" >> $log_file fi + unset previous_ping_ip_arr + previous_ping_ip_arr=("${ping_ip_arr[@]}") fi } usage() { @@ -123,12 +132,12 @@ if mkdir "$LOCK_DIR" 2> /dev/null ; then else datum=`date +"%d.%m.%Y"` - msg="[ Error ]: A previos instance of script \"`basename $0`\" seems already be running.\n\n Exiting now.." + msg="[ Error ]: A previous instance of script \"`basename $0`\" seems already be running.\n\n Exiting now.." echo -e "To:${admin_email}\n${content_type}\nSubject:DSL Script Error $company -- $datum\n\n${msg}\n" | /usr/sbin/sendmail -F "DSL Monitoring $company" -f $from_address $admin_email 2> /dev/null if $LOGGING_CONSOLE ; then echo "" - echo "[ Error ]: A previos instance script \"`basename $0`\" seems already be running." + echo "[ Error ]: A previous instance script \"`basename $0`\" seems already be running." echo "" echo " Exiting now.." echo "" @@ -209,6 +218,7 @@ for inet_device in "${online_devices_arr[@]}" ; do done declare -a ping_ip_arr; +declare -a previous_ping_ip_arr; #echo "--" @@ -308,8 +318,17 @@ while true ; do else failed=true for _key in ${!ping_ip_arr[@]} ; do - /sbin/ip rule add to ${ping_ip_arr[$_key]} table $rt_name - if ping -q -c2 ${ping_ip_arr[$_key]} >/dev/null 2>&1 ; then + if $DEBUG ; then + echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] route add -net ${ping_ip_arr[$_key]} netmask 255.255.255.255 gw $remote_gw_address" >> $log_file + fi + #/sbin/ip rule add to ${ping_ip_arr[$_key]} table $rt_name + route add -net ${ping_ip_arr[$_key]} netmask 255.255.255.255 gw $remote_gw_address + + if $DEBUG ; then + echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] ping4 -I $inet_device -q -c2 ${ping_ip_arr[$_key]}" >> $log_file + fi + #if ping -q -c2 ${ping_ip_arr[$_key]} >/dev/null 2>&1 ; then + if ping4 -I $inet_device -q -c2 ${ping_ip_arr[$_key]} >/dev/null 2>&1 ; then if $DEBUG ; then _local_gw=`curl -4 https://meine-ip.oopen.de 2> /dev/null` if [ -n "$_local_gw" ]; then @@ -317,12 +336,22 @@ while true ; do fi echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] Ping test (to ${ping_ip_arr[$_key]}) for device \"${inet_device}\" was successful." >> $log_file fi - /sbin/ip rule del to ${ping_ip_arr[$_key]} table $rt_name + + if $DEBUG ; then + echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] route del -net ${ping_ip_arr[$_key]} netmask 255.255.255.255 gw $remote_gw_address" >> $log_file + fi + #/sbin/ip rule del to ${ping_ip_arr[$_key]} table $rt_name + route del -net ${ping_ip_arr[$_key]} netmask 255.255.255.255 gw $remote_gw_address failed=false device_is_online=true break fi - /sbin/ip rule del to ${ping_ip_arr[$_key]} table $rt_name + + if $DEBUG ; then + echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] route del -net ${ping_ip_arr[$_key]} netmask 255.255.255.255 gw $remote_gw_address" >> $log_file + fi + #/sbin/ip rule del to ${ping_ip_arr[$_key]} table $rt_name + route del -net ${ping_ip_arr[$_key]} netmask 255.255.255.255 gw $remote_gw_address done if $failed ; then echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Ping test for device \"${inet_device}\" failed" >> $log_file