Changeset 14164 in hybrid for branches/releng-11/nanobsd


Ignore:
Timestamp:
May 9, 2018, 9:43:34 AM (7 years ago)
Author:
rick
Message:

Fix failure on definition of multiple nameservers

If /etc/resolv.conf contains multiple identical nameservers the script will
bail out due to multiple matches with grep and awk. Making script more robust
by adding uniqueness checking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/releng-11/nanobsd/files/tools/nameserver-shuffle

    r14145 r14164  
    2828# Get enabled DYNAMIC LIST nameservers
    2929sed "1,\+$TAG+d" /etc/resolv.conf > $DYNLIST || exit 1
    30 NAMESERVERS=`awk '/^nameserver/ {print $2}' $DYNLIST` || exit 1
     30NAMESERVERS=`awk '/^nameserver/ {print $2}' $DYNLIST | sort -u` || exit 1
    3131
    3232# Only do something if we have dynamic nameservers
     
    4848 
    4949  # Output sorted list
    50   NAMESERVERS=`sort -n $RESULTLIST | awk '{print $2}'`
     50  NAMESERVERS=`sort -n $RESULTLIST | uniq -f 1 | awk '{print $2}'`
    5151  for NAMESERVER in $NAMESERVERS; do
    52     QUERY_TIME=`grep "${NAMESERVER}$" $RESULTLIST | cut -d' ' -f1`
    53     [ $QUERY_TIME = "9999" ] && STATUS="Query time: down" || STATUS="Query time: $QUERY_TIME"
     52    QUERY_TIME=`grep -m 1 "${NAMESERVER}$" $RESULTLIST | cut -d' ' -f1`
     53    [ "$QUERY_TIME" = "9999" ] && STATUS="Query time: down" || STATUS="Query time: $QUERY_TIME"
    5454    # awk magic to get maximum length of comment field (for display purposes).
    5555    ML=`awk '/^nameserver/ {l=length($4);if (l>ml){ml=l}}END{print ml}' $DYNLIST`
     
    6767
    6868  # Update unbound forwarders list
    69   unbound-control forward $(awk '/^nameserver 172/ {print $2}' /etc/resolv.conf | head -3)
     69  unbound-control forward $(awk '/^nameserver 172/ {print $2}' /etc/resolv.conf | uniq | head -3)
    7070fi
Note: See TracChangeset for help on using the changeset viewer.