Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 06 Nov 2017 18:32:17 -0500
From:      Ernie Luzar <luzar722@gmail.com>
To:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Need help with rc.d script
Message-ID:  <5A00F101.8040708@gmail.com>

next in thread | raw e-mail | index | archive | help
I wrote this sh script today for dynamic dns ip updates.
When I use service dynip start command it just hangs there.
Need pointer to what I am doing wrong.

Here are the 2 scripts in question:

Script started on Mon Nov  6 18:19:18 2017
/root/bin >cat /usr/local/bin/dynip
#!/bin/sh
   #
   # Script to update the dynamic DNS pointer at your dynamic DNS 
hosting site.
   # This script runs continually and on a user defined timed cycle will
   # check the dynamic ip address of the interface facing the public 
internet
   # to determin if it has changed. If it has changed the browser URL format
   # is used to update the DNS pointer IP address at the dynamic DNS 
hosting
   # site that is hosting your Fully qualified domain to the newly changed
   # ip address.
   #
   # The default browser URL format being used is for NameCheap 
(namecheap.com).
   # NOTE: Most DNS hosting sites that provide dynamic DNS services use a
   # variation of the default browser URL format used here. A simple user
   # substitution to the "wget" command for the browser URL format used 
by your
   # dynamic DNS hosting site will allow this script to work for you.

   prev_ip_file="/usr/local/etc/dynip"

   # Cycle time to wait between ip checks.
   #elapse_time="7200" # 7200 seconds = 2 hours
   #elapse_time="3600" # 3600 seconds = 1 hour
   #elapse_time="1800" # 1800 seconds = 30 minutes
   #elapse_time="900"  # 1800 seconds = 15 minutes
   #elapse_time="600"  # 600  seconds = 10 minutes
   #elapse_time="300"  # 300  seconds =  5 minutes
   elapse_time="10"


   # Find the NIC device name of the NIC connected to the public internet.
   # The default interface obtained from route command is the one connected
   # to the public internet.
   #
   nic_devicename="$(route get -inet default 2> /dev/null | \
   grep -o "interface.*" | cut -d ' ' -f 2)"
   ##echo "nic_devicename = ${nic_devicename}"


   # Get the IP address assigned to that NIC device name.
   #
   nic_ip="$(ifconfig $nic_devicename inet | \
   grep -o "inet.*" | cut -d ' ' -f 2)"
   #echo "nic_ip1 = ${nic_ip}"


   # On start up get the last recorded ip address in use and populate 
variable
   # with its value.
   #
   if [ -f "${prev_ip_file}" ]; then
      prev_ip="$(cat ${prev_ip_file})"
   else
      prev_ip="0.0.0.0"
      echo "${prev_ip}" > ${prev_ip_file}
   fi
   #echo "prev_ip = $prev_ip"

   # This is the continuous loop checking the current ip address to
   # to determin if it changed.
   while [ 1 ]; do
     # Get the IP address assigned to that NIC device name.
     nic_ip="$(ifconfig $nic_devicename inet | \
     grep -o "inet.*" | cut -d ' ' -f 2)"
     #echo "nic_ip2 = ${nic_ip}"

     if [ "${prev_ip}" != "${nic_ip}" ]; then
       # Update dynamic DNS hosting site with new ip address.
       website="https://dynamicdns.park-your-domain.com/update?"
       dyn_host="host=home-fbsd&domain=host.xxxxxxx.com"
       password="&password=a3e0ffc2274746b29ceaf126d59e51c1"
       url="$website$dyn_host$password"
       #echo "$url"
       /usr/local/bin/wget -O /var/log/namecheap.dynip.update.log -q "$url"
       #echo "rtn-code = $?"
       if [ $? -ne 0 ]; then
         echo "Error: /usr/local/bin/wget command failed."
         exit 3
       fi
     #echo "${nic_ip}" > ${prev_ip_file}
     prev_ip="${nic_ip}"
     fi
     sleep ${elapse_time}
   done


/root/bin cat /usr/local/etc/rc.d/dynip
#!/bin/sh
#
#
# PROVIDE: dynip
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable dynip:
#
# dynip_enable="YES"
#


. /etc/rc.subr
name=dynip
rcvar=dynip_enable
command="/usr/local/bin/${name}"
run_rc_command "$1"






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5A00F101.8040708>