Line break in script

Hi,

I created a script like this, unfortunately the result always has a line break.

The content of LATEST.7 is 7.12.1 WITHOUT a line book

/system script add name="MikrotikUpdateVersionCheck" source={
     :global arch [/system resource get architecture-name]
     :global server "http://192.168.111.1/mikrotik_npks"
     :global latest version
     :global currentVersion [/system package update get installed-version]

     /tool fetch url=($server . "/LATEST.7") mode=http dst-path="latestVersion.txt"
     :set latestVersion [/file get latestVersion.txt contents]

     :if ($latestVersion != $currentVersion) do={
         /system script run MikrotikUpdateDownload
     }

     :put "Architecture: $arch"
     :put "Server: $server"
     :put "Latest version: $latestVersion"
     :put "Current version: $currentVersion"
}

The Result is:

http://192.168.111.1/mikrotik_npks/routeros-7.12.1
-mipsbe.npk

Script that you posted doesn’t generate URL mentioned at the end, it is hard to tell how you get new line in it unless you expose script that generates it, also attach latestVersion.txt file for troubleshooting.

Oh sorry,

here is the second Script

/system script add name="MikrotikUpdateDownload" source={
    :global arch
    :global server
    :global latestVersion
    :global downloadResult
    :global url

    :set url ($server . "/routeros-" . $latestVersion . "-" . $arch . ".npk")
    :put "Download-URL: $url"
    :set downloadResult [/tool fetch url=$url mode=http dst-path=("routeros-" . $latestVersion . "-" . $arch . ".npk") as-value]
    :put "Download-Ergebnis: $downloadResult"
}

My LATEST.7 file only contains the version number 7.12.1. I also deleted all the empty lines and empty fields here.
But the forum won’t let me upload the LATEST.7 because it’s probably not a TXT.
latestVersion.txt (7 Bytes)

As I assumed latestVersion.txt contains new line
latestVersion.txt.png
You will need to trim new line character, like

:local latestVersion [/file get latestVersion.txt contents]
:local l [:len $latestVersion]
:local lcp ($l - 1)
:if ([:pick $latestVersion $lcp $l] = "\n") do={
  :set latestVersion [:pick $latestVersion 0 $lcp]
}

You can omit check last character is new line condition if you are sure that new line character will always be at the end. Also this just covers \n (unix) line ending, not \r\n (dos/win).

For retrieve version number from MikroTik:
http://forum.mikrotik.com/t/script-to-update-routeros-after-x-days-of-release/170000/27

Why you useless download the file on the board without simply read the value inside the file on the url?
{

Actually the returned data end with \n. If for some reason on future \n is correctly removed, this prevent the script fail.

:local vchannel “stable” ; # can be: [long-term | stable | testing | development]
:local lastv7 (“$([/tool fetch url=“https://upgrade.mikrotik.com//routeros/NEWESTa7.$vchannel” as-value output=user]->“data”)\n”)
:local lastv7ver [:pick $lastv7 0 [:find $lastv7 “_” -1]]
:local currver [/system/package get [find where name=“routeros”] version]
:if ($lastv7ver != $currver) do={
:local lastv7build [:totime [:pick $lastv7 ([:find $lastv7 “_” -1] + 1) [:find $lastv7 “\n” -1]]]
:local currtime [:timestamp]
:local daysdiff ($currtime - $lastv7build)
:local vdays 30d
:put “The Installed version is $currver and the Latest version $lastv7ver is old $daysdiff days”
:if ($daysdiff > $vdays) do={
:put “Performing update: Latest is older than $vdays days”
# /sys pack up; check; in
} else={
:put “Not updated: Waiting Latest for be older than $vdays days”
}
} else={
:put “The Installed and Latest version are the same $currver”
}

}