Page 1 of 1

Add script by telnet

Posted: Mon Mar 09, 2015 5:37 pm
by dahonora
Hello! I'm trying to add this script by telnet (I only have activate telnet in the router). I toke the script from this site http://wiki.mikrotik.com/wiki/Dynamic_D ... behind_NAT. When I add the script it appears like Invalid, so it doesn't work and I don't know why. Ideas? Thanks for your time!

/system script
add name=OpenDNS policy=write,read,test,policy source="#\r\
\n# DNSoMatic automatic DNS updates\r\
\n#--------------- Change Values in this section to match your setup ------------------\r\
\n# User account info of DNSoMatic\r\
\n:local maticuser \"honorato.daniel@gmail.com\"\r\
\n:local maticpass \"***************\"\r\
\n# Set the hostname or label of network to be updated. This is the part after the double colon (::) on the DNSoMatic services page.\r\
\n# Hostnames with spaces are unsupported. Replace the value in the quotations below with your host names.\r\
\n# To specify multiple hosts, separate them with commas. \r\
\n# Use \"all.dnsomatic.com\" for the matichost to update all items in dnsomatic with this IP.\r\
\n:local matichost \"all.dnsomatic\"\r\
\n#------------------------------------------------------------------------------------\r\
\n# No more changes need\r\
\n:global previousIP;\r\
\n:log info \"Fetching current IP\"\r\
\n# Get the current public IP using DNS-O-Matic service.\r\
\n/tool fetch url=\"http://myip.dnsomatic.com/\" mode=http dst-path=mypublicip.txt\r\
\n# Read the current public IP into the currentIP variable.\r\
\n:local currentIP [/file get mypublicip.txt contents]\r\
\n:log info \"Fetched current IP as $currentIP\"\r\
\n \r\
\n:if ($currentIP != $previousIP) do={\r\
\n :log info \"DNSoMatic: Update needed\"\r\
\n :set previousIP $currentIP \r\
\n# The update URL. Note the \"\3F\" is hex for question mark. Required since is a special character in commands.\r\
\n :local url \"http://updates.dnsomatic.com/nic/update ... =NOCHG\"\r\
\n :local matichostarray;\r\
\n :set matichostarray [:toarray $matichost];\r\
\n :foreach host in=$matichostarray do={\r\
\n :log info \"DNSoMatic: Sending update for $host\"\r\
\n /tool fetch url=($url . \"&hostname=$host\") user=$maticuser password=$maticpass mode=http dst-path=(\"dnsomaticupdate-\" . $host . \".txt\")\r\
\n :log info \"DNSoMatic: Host $host updated on DNSoMatic with IP $currentIP\"\r\
\n }\r\
\n} else={\r\
\n :log info \"DNSoMatic: Previous IP $previousIP and current IP equal, no update need\"\r\
\n}

Re: Add script by telnet

Posted: Tue Mar 10, 2015 2:59 pm
by PaulsMT
Seems there is missing { at the beginning of script.

Try to add script again, just add braces from both sides { <YOUR SCRIPT> }

Re: Add script by telnet

Posted: Tue Mar 10, 2015 5:42 pm
by dahonora
I got it. I was missing a " at the end. Thank you anyway. The series of { } was ok.
Now I have another problem. When running the script I get an error "syntax error (line 22 column 8 )". So if I count well I have an error in this line \n:if ($currentIP != $previousIP) do={\r\. I can't see anything bad here. May be I forgot something?

Re: Add script by telnet

Posted: Fri Mar 20, 2015 9:24 am
by dahonora
It has been some time... but if anyone will help I find the reason of the error. I was missing a '\' before all the '$'.
Now I can run it... anyway it doesn't do what he is suppose... it's confuse...

status: failed

failure: closing connection: <connection failed> 216.146.38.70:80 (4)