Fix some minor error. Add debug messages.
This commit is contained in:
		@@ -11,6 +11,11 @@ netconfig_script=/usr/local/sbin/netconfig.sh
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
log_file=/var/log/check_net.log
 | 
					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)
 | 
					# - Put in your DSL devices (refers to your network configuration)
 | 
				
			||||||
# - youe wish be congigured by that script
 | 
					# - youe wish be congigured by that script
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										41
									
								
								check_net.sh
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								check_net.sh
									
									
									
									
									
								
							@@ -60,10 +60,19 @@ set_ping_addresses () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
   if [ ${#ping_ip_arr[@]} -lt 1 ]; then
 | 
					   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
 | 
					      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
 | 
					   else
 | 
				
			||||||
      if $DEBUG ; then
 | 
					      if $DEBUG ; then
 | 
				
			||||||
         echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info  ] IP-Addresses for ping tests set to ${ping_ip_arr[@]}" >> $log_file 
 | 
					         echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info  ] IP-Addresses for ping tests set to ${ping_ip_arr[@]}" >> $log_file 
 | 
				
			||||||
      fi
 | 
					      fi
 | 
				
			||||||
 | 
					      unset previous_ping_ip_arr
 | 
				
			||||||
 | 
					      previous_ping_ip_arr=("${ping_ip_arr[@]}")
 | 
				
			||||||
   fi
 | 
					   fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
usage() { 
 | 
					usage() { 
 | 
				
			||||||
@@ -123,12 +132,12 @@ if mkdir "$LOCK_DIR" 2> /dev/null ; then
 | 
				
			|||||||
else
 | 
					else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   datum=`date +"%d.%m.%Y"`
 | 
					   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
 | 
					   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
 | 
					   if $LOGGING_CONSOLE ; then
 | 
				
			||||||
      echo ""
 | 
					      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 ""
 | 
				
			||||||
      echo "           Exiting now.."
 | 
					      echo "           Exiting now.."
 | 
				
			||||||
      echo ""
 | 
					      echo ""
 | 
				
			||||||
@@ -209,6 +218,7 @@ for inet_device in "${online_devices_arr[@]}" ; do
 | 
				
			|||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
declare -a ping_ip_arr;
 | 
					declare -a ping_ip_arr;
 | 
				
			||||||
 | 
					declare -a previous_ping_ip_arr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#echo "--"
 | 
					#echo "--"
 | 
				
			||||||
@@ -308,8 +318,17 @@ while true ; do
 | 
				
			|||||||
         else
 | 
					         else
 | 
				
			||||||
            failed=true
 | 
					            failed=true
 | 
				
			||||||
            for _key in ${!ping_ip_arr[@]} ; do
 | 
					            for _key in ${!ping_ip_arr[@]} ; do
 | 
				
			||||||
               /sbin/ip rule add to ${ping_ip_arr[$_key]} table $rt_name
 | 
					               if $DEBUG ; then
 | 
				
			||||||
               if ping -q -c2 ${ping_ip_arr[$_key]} >/dev/null 2>&1 ; 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
 | 
					                  if $DEBUG ; then
 | 
				
			||||||
                     _local_gw=`curl -4 https://meine-ip.oopen.de 2> /dev/null` 
 | 
					                     _local_gw=`curl -4 https://meine-ip.oopen.de 2> /dev/null` 
 | 
				
			||||||
                     if [ -n "$_local_gw" ]; then
 | 
					                     if [ -n "$_local_gw" ]; then
 | 
				
			||||||
@@ -317,12 +336,22 @@ while true ; do
 | 
				
			|||||||
                     fi
 | 
					                     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
 | 
					                     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
 | 
					                  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
 | 
					                  failed=false
 | 
				
			||||||
                  device_is_online=true
 | 
					                  device_is_online=true
 | 
				
			||||||
                  break
 | 
					                  break
 | 
				
			||||||
               fi
 | 
					               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
 | 
					            done
 | 
				
			||||||
            if $failed ; then
 | 
					            if $failed ; then
 | 
				
			||||||
               echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Ping test for device \"${inet_device}\" failed" >> $log_file
 | 
					               echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Ping test for device \"${inet_device}\" failed" >> $log_file
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user