On Sat, Dec 3, 2016 at 4:29 PM, Carlos E. R. <robin.listas@telefonica.net> wrote:
On 2016-12-03 14:59, Carlos E. R. wrote:
On 2016-12-03 09:07, Per Jessen wrote:
Carlos E. R. wrote:
I just have to finish the cronjob script.
I have a coding problem.
I obtain the current IP this way from the router:
/usr/local/bin/GetIpFromRouter.exp > /run/DDNS/router_output.log CURRENTIP=`grep PPPoE /run/DDNS/router_output.log | awk '{ print $10}'`
The first line is an expect script that does a telnet to the router, issues the command "wan show", which produces a text that includes the IP. The second line extracts the IP from the line, like this one:
N/A 1 6 ppp0.1 PPPoE Disable Enable Disable Connected 192.168.1.1\r
The problem is that as the router ends the line in non unix format, the variable awk gets is "192.168.1.1^M".
How can I remove that "^M"?
It produces several errors in the script.
I don't know awk, so I don't know how the awk code could be modified:
echo line | awk '{ print $10}'
cut? I don't see how to extract till the last char minus one.
Convert the entire telnet session to Linux format? dos2unix? No, does not work.
This is the code:
usr/local/bin/GetIpFromRouter.exp > /run/DDNS/router_output.log 2> /run/DDNS/router_output_err.log # remove ^M chars from eol /usr/bin/dos2unix /run/DDNS/router_output_err.log CURRENTIP=`grep PPPoE /run/DDNS/router_output.log | awk '{ print $10}'` 2> /run/DDNS/router_output_greperr.log
echo "Last IP: $LASTKNOWNIP" echo "Current IP: $CURRENTIP"
echo "Last IP: $LASTKNOWNIP Current IP: $CURRENTIP"
The last echo produces this output:
cer@Isengard:~> TrackIpAndUpdateDDNS dos2unix: converting file /run/DDNS/router_output_err.log to Unix format ... Last IP: 83.36.42.230 Current IP: 83.36.42.230 Current IP: 83.36.42.230 <<= cer@Isengard:~>
The text "Last IP ..." in the last line is overwritten with "Current IP..." because it contains a carriage return.
So the problem is in the awk code, it cuts too late.
sed? I don't know how to use it.
I could try appending an space to the line, perhaps... How?
Ideas?
tr -d "\r", perhaps: /usr/local/bin/GetIpFromRouter.exp | tr -d "\r" > /run/DDNS/router_output.log -- Mark Goldstein -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org