From owner-freebsd-questions@freebsd.org Thu Nov 9 15:13:33 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 7A349E53077 for ; Thu, 9 Nov 2017 15:13:33 +0000 (UTC) (envelope-from kraduk@gmail.com) Received: from mail-qk0-x22e.google.com (mail-qk0-x22e.google.com [IPv6:2607:f8b0:400d:c09::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 335766A632 for ; Thu, 9 Nov 2017 15:13:33 +0000 (UTC) (envelope-from kraduk@gmail.com) Received: by mail-qk0-x22e.google.com with SMTP id 2so7248892qkg.13 for ; Thu, 09 Nov 2017 07:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=VYEfe6/80P1TeyKGoqfrXHv3qA5JbjfPsu4r3erD6Ek=; b=AC5kccFAO9067Np/jSaFJSJvTqzW7PmW+11J+aicogiGx6eZ18oX5THolT/5UlUr90 2ux7D51SYmTGxM+DI1jxGBBi06DyS4OTyao+Ro1yjM2ZN22zjWuqtXIXpe15ViVUxK06 2YwsrLdmFfPrOFZ1fnQEkS3VvP5gX54MG6u5BKSRM9ug6GB2nxQztq9n1zMu3CprQKRl DqwpYgTi54xp7vqbQeKURwr0ms5slYnjOO5W2paEacZtgNn3mMtcHR4Zy8EF0GGbtgbL +Vd4+5z2KNcBNUUwfvqnfoi9U0ZvDkZG3wMQsDeXylTE7zdhMI5lZ7+IOphDg4C/Gr5t Hc8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=VYEfe6/80P1TeyKGoqfrXHv3qA5JbjfPsu4r3erD6Ek=; b=CXX/WMbTBs0eHv9BI1LER7Hy73RBjCkq+3oGU7hCSDaiF1Ti4YBH3gwuKdigdnLp21 mneonEQao1vHOM2yH8WKz0pmFYG9e1bf7lWuhaAUBUhuLr6lRjY8qW+Mvt8635cPLvXx NqmUxZ5pOTZblQ2iKHJIEeA//CTopN/BYSNLQpFUWLNK3sgkEoTTZxVI4MNg8jaCYXVv yKiRcZpPscSADersFk3Sex6UammuseUKdeOoWf2FXSJ/Tjb6oanqj+i2MXuhNBoJnqeE 070B2Ocf2ltjwS9uveKBpbxgQw7vgip/p7diT6E7afj003kX/xQf25DLRCrIAXBm1/y/ x6WA== X-Gm-Message-State: AJaThX5SVFcfEtR0OSiHq31+yzOU2++WjaFbCjrbY6szAci8jbkz6fUt awCRacd2XswNCeB2qSkQyFSdz2ePoNrPw+u6T8U= X-Google-Smtp-Source: AGs4zMYa9xITQUYYPxqUTzXQ6ER9iswfbVWHVFeXsUteheCQJCk+cHnY4l2QNpQKxZDpbBC0MCsvUEMBWlpLcefixUo= X-Received: by 10.55.160.135 with SMTP id j129mr1191813qke.274.1510240412270; Thu, 09 Nov 2017 07:13:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.20.65 with HTTP; Thu, 9 Nov 2017 07:13:31 -0800 (PST) In-Reply-To: <20171108021900.W9710@sola.nimnet.asn.au> References: <20171108021900.W9710@sola.nimnet.asn.au> From: krad Date: Thu, 9 Nov 2017 15:13:31 +0000 Message-ID: Subject: Re: Need help with rc.d script To: Ian Smith Cc: Ernie Luzar , FreeBSD Questions Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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: Thu, 09 Nov 2017 15:13:33 -0000 true, but it will probably handle it better, unless you reinvent the wheel, and it is part of the base OS On 7 November 2017 at 15:38, Ian Smith wrote: > 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 > _______________________________________________ > freebsd-questions@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions- > unsubscribe@freebsd.org" >