Whats wrong in my script: "Fetching my public IP from url=icanhazip.com"?

Here is my script. The first line shows syntax error:

:local currentIP [/tool fetch url="http://icanhazip.com" as-value output=user]->"data";
:local timestamp [/system clock get time];
:local date [/system clock get date];
:local logEntry ("Public IP: $currentIP at $date $timestamp");

The first syntax error is give by this part of the script: “url="http://”. It helps if I remove replace it with "url=“http://”. However, I get error and it seems to be related to the very last part of the first line. Go figure…?

Hi,

The parenthesis around the → operator is missing. It should be:

:local currentIP ([/tool fetch url="http://icanhazip.com" as-value output=user]->"data");

BTW. I removed the escaping of the quotes to be able to run the command from CLI.

If you use the build in editor from the CLI, the above error comes out pretty clear in the syntax highlighting.

Also the same result can be achieved like this:

 
 :local currentIP [/ip/cloud/get public-address]

Thank you. Both worked.