From cfc96da133db699662758e1959deab2d16bcdbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20Gei=C3=9Fler?= Date: Thu, 21 Apr 2016 23:09:38 +0200 Subject: [PATCH 1/4] replace occurences of "1>/dev/null 2>&1" by "&> /dev/null" --- nsupdate.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nsupdate.sh b/nsupdate.sh index fa4016a..bef8cc3 100755 --- a/nsupdate.sh +++ b/nsupdate.sh @@ -25,16 +25,15 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # check required tools -command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl but it's not installed. Note: all needed items are listed in the README.md file."; exit 1; } -command -v awk >/dev/null 2>&1 || { echo >&2 "I require awk but it's not installed. Note: all needed items are listed in the README.md file."; exit 1; } -command -v drill >/dev/null 2>&1 || command -v nslookup >/dev/null 2>&1 || { echo >&2 "I need drill or nslookup installed. Note: all needed items are listed in the README.md file."; exit 1; } +command -v curl &> /dev/null || { echo >&2 "I require curl but it's not installed. Note: all needed items are listed in the README.md file."; exit 1; } +command -v awk &> /dev/null || { echo >&2 "I require awk but it's not installed. Note: all needed items are listed in the README.md file."; exit 1; } +command -v drill &> /dev/null || command -v nslookup &> /dev/null || { echo >&2 "I need drill or nslookup installed. Note: all needed items are listed in the README.md file."; exit 1; } LOG=$0.log SILENT=NO # Check if there are any usable config files -if ls $(dirname $0)/nsupdate.d/*.config 1> /dev/null 2>&1; then - +if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then # Loop through configs for f in $(dirname $0)/nsupdate.d/*.config do From 899af068379657ff48c00cd5653da1f17e205b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20Gei=C3=9Fler?= Date: Thu, 21 Apr 2016 23:31:04 +0200 Subject: [PATCH 2/4] replace single brackets by double ones (more modern style) --- nsupdate.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nsupdate.sh b/nsupdate.sh index bef8cc3..1a574a5 100755 --- a/nsupdate.sh +++ b/nsupdate.sh @@ -37,7 +37,7 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then # Loop through configs for f in $(dirname $0)/nsupdate.d/*.config do - if [ "$SILENT" == "NO" ]; then + if [[ "$SILENT" == "NO" ]]; then echo "Starting nameserver update with config file $f" fi ## Set record type to IPv4 @@ -65,7 +65,7 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then NSLOOKUP=$(drill $DOMAIN @ns.inwx.de $TYPE | head -7 | tail -1 | awk '{print $5}') fi else - if [[ "$TYPE" == "MX" ]]; then + if [[ "$TYPE" == "MX" ]]; then PART_NSLOOKUP=$(nslookup -sil -type=$TYPE $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f5) NSLOOKUP=${PART_NSLOOKUP%"."} else @@ -113,8 +113,8 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then " - - if [ ! "$NSLOOKUP" == "$WAN_IP" ]; then + + if [[ "$NSLOOKUP" != "$WAN_IP" ]]; then curl -silent -v -XPOST -H"Content-Type: application/xml" -d "$API_XML" https://api.domrobot.com/xmlrpc/ echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG elif [ "$SILENT" == "NO" ]; then From 107ba9ad83013ebb5616301cb7a63d86e41b6cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20Gei=C3=9Fler?= Date: Thu, 21 Apr 2016 23:34:04 +0200 Subject: [PATCH 3/4] improve indentation using $(...) instead of `...` is a better style --- nsupdate.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/nsupdate.sh b/nsupdate.sh index 1a574a5..144a323 100755 --- a/nsupdate.sh +++ b/nsupdate.sh @@ -59,22 +59,22 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then if [[ "$USE_DRILL" == "YES" ]]; then if [[ "$TYPE" == "MX" ]]; then - echo looking up MX records with drill currently not supported! - exit 1; - else - NSLOOKUP=$(drill $DOMAIN @ns.inwx.de $TYPE | head -7 | tail -1 | awk '{print $5}') - fi + echo looking up MX records with drill currently not supported! + exit 1 + else + NSLOOKUP=$(drill $DOMAIN @ns.inwx.de $TYPE | head -7 | tail -1 | awk '{print $5}') + fi else if [[ "$TYPE" == "MX" ]]; then - PART_NSLOOKUP=$(nslookup -sil -type=$TYPE $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f5) - NSLOOKUP=${PART_NSLOOKUP%"."} + PART_NSLOOKUP=$(nslookup -sil -type=$TYPE $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f5) + NSLOOKUP=${PART_NSLOOKUP%"."} else - NSLOOKUP=$(nslookup -sil -type=$TYPE $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f2) - fi + NSLOOKUP=$(nslookup -sil -type=$TYPE $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f2) + fi fi # WAN_IP=`curl -s -$CONNECTION_TYPE ${IP_CHECK_SITE}| grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'` - WAN_IP=`curl -s -$CONNECTION_TYPE ${IP_CHECK_SITE}` + WAN_IP=$(curl -s -$CONNECTION_TYPE ${IP_CHECK_SITE}) API_XML=" @@ -131,5 +131,6 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then unset INWX_DOMAIN_ID done else - echo "There does not seem to be any config file available in $(dirname $0)/nsupdate.d/." ; exit 1; + echo "There does not seem to be any config file available in $(dirname $0)/nsupdate.d/." + exit 1 fi From a01d99ab9ae9bfb5573540fd2196f1639c55af0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20Gei=C3=9Fler?= Date: Thu, 21 Apr 2016 23:36:34 +0200 Subject: [PATCH 4/4] the silent mode did still output several lines of text. This commit fixes it mostly. --- nsupdate.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nsupdate.sh b/nsupdate.sh index 144a323..b7e4517 100755 --- a/nsupdate.sh +++ b/nsupdate.sh @@ -115,10 +115,14 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then " if [[ "$NSLOOKUP" != "$WAN_IP" ]]; then - curl -silent -v -XPOST -H"Content-Type: application/xml" -d "$API_XML" https://api.domrobot.com/xmlrpc/ - echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG - elif [ "$SILENT" == "NO" ]; then - echo "$(date) - No update needed for $DOMAIN. Current IP: "$NSLOOKUP >> $LOG + curl -s -XPOST -H "Content-Type: application/xml" -d "$API_XML" https://api.domrobot.com/xmlrpc/ + if [[ "$SILENT" == "NO" ]]; then + echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG + fi + else + if [[ "$SILENT" == "NO" ]]; then + echo "$(date) - No update needed for $DOMAIN. Current IP: "$NSLOOKUP >> $LOG + fi fi unset DOMAIN @@ -129,6 +133,7 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then unset INWX_PASS unset INWX_USER unset INWX_DOMAIN_ID + unset API_XML done else echo "There does not seem to be any config file available in $(dirname $0)/nsupdate.d/."