On 2016-12-03 16:02, Yamaban wrote:
On Sat, 3 Dec 2016 15:29, Carlos E. R. <robin.listas@...> wrote:
Let's try "simple" first:
[code of cron-script] # make sure LASTKNOWNIP is clean: tempip=`echo $LASTKNOWNIP | tr -d '\r'` LASTKNOWNIP=$tempip
You are right, the last IP was stored with the error.
# get actual info from router, log errors /usr/local/bin/GetIpFromRouter.exp > /run/DDNS/router_output.log 2> /run/DDNS/router_output_err.log
# grep out PPoE line, catch out wan ip, log errors CURRENTIP=`grep PPPoE /run/DDNS/router_output.log | tr -d '\r' | awk '{print $10}'` 2> /run/DDNS/router_output_greperr.log
echo "Last IP: '$LASTKNOWNIP' Current IP: '$CURRENTIP'" [/code]
that code (which is mostly what You'he shown) should give you:
Last IP: 'MY_IP' Current IP: 'MY_IP'
Ok, now what did I different:
1. Added cleanup of LASTKNOWNIP, most likely it still will have that added '\r' or '^M', lets remove that.
Yes, it is so.
2. Removed dos2unix of the router_output_err.log, why the error log??
Just in case there is some error, know about it. The intention is to email those to myself. Thus if the script fails somehow while I'm out, I still get an email with info, enough info to access via the IP and correct problem. Hopefully! We all know how sure things fail in computing ;-)
3. Added cleanup to the output of grep, before awk.
How did I do that cleanup? Using the most simple tool available: "tr"
Right! I forgot about that tool. Thanks! Now I have a different unrelated problem: dyn.dns24.ch says I'm not authorized. Why? It worked before. That's with wget. curl appears to works, but doesn't really say: cer@isengard:~> curl --anyauth -u USER:PASS "http://dyn.dns24.ch/update?hostname=MY_HOST.dyndns24.ch&type=A&data=IPNUMBER" 0000 Transaction successful, # affected row(s) = 0 cer@isengard:~> The output is misleading, see wget: cer@isengard:~> wget --user=LOGIN --password=PASSWORD "http://dyn.dns24.ch/update?hostname=MY_HOST.dyndns24.ch&type=A&data=MY_IP" --2016-12-03 16:43:58-- http://dyn.dns24.ch/update?hostname=MY_HOST.dyndns24.ch&type=A&data=MY_IP Resolving dyn.dns24.ch (dyn.dns24.ch)... 185.85.251.248, 2a03:7520:4c68:2::e047 Connecting to dyn.dns24.ch (dyn.dns24.ch)|185.85.251.248|:80... connected. HTTP request sent, awaiting response... 401 Unauthorized Reusing existing connection to dyn.dns24.ch:80. HTTP request sent, awaiting response... 200 OK Length: 51 [text/plain] Saving to: ‘update?hostname=MY_HOST.dyndns24.ch&type=A&data=MY_IP’ 100%[==================================================================================================>] 51 --.-K/s in 0s 2016-12-03 16:43:58 (4,29 MB/s) - ‘update?hostname=MY_HOST.dyndns24.ch&type=A&data=MY_IP’ saved [51/51] cer@isengard:~> Dunno, there is a 401 Unauthorized, then a 200 OK. I don't know what happened. The saved "file" from above wget says: 0000 Transaction successful, # affected row(s) = 0 Maybe that means success. :-? I need nutrients and rest. O:-) -- Cheers / Saludos, Carlos E. R. (from 13.1 x86_64 "Bottle" at Telcontar)