From owner-freebsd-questions@freebsd.org Tue Nov 7 15:38:59 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AFE8BE5BFB2 for ; Tue, 7 Nov 2017 15:38:59 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 12AF66FA82 for ; Tue, 7 Nov 2017 15:38:58 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id vA7FcsUu068402; Wed, 8 Nov 2017 02:38:55 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Wed, 8 Nov 2017 02:38:54 +1100 (EST) From: Ian Smith To: Ernie Luzar cc: freebsd-questions@freebsd.org Subject: Re: Need help with rc.d script In-Reply-To: Message-ID: <20171108021900.W9710@sola.nimnet.asn.au> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Nov 2017 15:38:59 -0000 In freebsd-questions Digest, Vol 701, Issue 2, Message: 18 On Mon, 06 Nov 2017 18:32:17 -0500 Ernie Luzar wrote: > 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. I'm going to cut to things that might be problematic .. > Script started on Mon Nov 6 18:19:18 2017 > /root/bin >cat /usr/local/bin/dynip > #!/bin/sh [..] > 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)" You do not need the outermost double quotes here, and sh could think the first one ends at the next one encountered (on "interface). > ##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)" Ditto, just not needed, or you can likely use single quotes for'inet.*' > #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 More portable (for any shell) is 'while true; 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 You do NOT need to use daemon, all you need to do is replace done with done & and perhaps test to be clear that's working, echo "dynip script done" exit 0 So that the script and so run_rc_command will complete, leaving the "while .. done &" subshell running in background. cheers, Ian