Does anyone have a solution to take a script and convert it so it can be be added in a terminal window?
For example, if I have the following script named “script1”:
# Get NTP status
# ----------------------------------
:local ntpstatus ""
:if ([:len [/system package find where !disabled and name=ntp]] > 0 or [:tonum [:pick [/system resource get version] 0 1]] > 6) do={
:set ntpstatus [/system ntp client get status]
} else={
:if ([:typeof [/system ntp client get last-update-from]] = "nil") do={
:set ntpstatus "using-local-clock"
} else={
:set ntpstatus "synchronized"
}
}
:log info message="script=ntp status=$ntpstatus"
I would like to be able to convert it to the following so that the /system/script/add command can be inside another script:
/system script add dont-require-permissions=no name=WoL-Activation owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source="# Get NTP status]\r\
\n # ----------------------------------\r\
\n:local ntpstatus ;\r\
\n:if ([:len [/system package find where !disabled and name=ntp]] > 0 or [:tonum [:pick [/system resource get version] 0 1]] > 6) do={\r\
\n :set ntpstatus [/system ntp client get status]\r\
\n} else={\r\
\n :if ([:typeof [/system ntp client get last-update-from]] = "nil") do={\r\
\n :set ntpstatus "using-local-clock"\r\
\n } else={\r\
\n :set ntpstatus "synchronized"\r\
\n }\r\
\n}\r\
\n:log info message="script=ntp status=$ntpstatus" \r\
A different (but related to the main project) question: the code immediately above (with the /r/ and /n added) fails with the quotation marks (") after “ntpstatus” And, if I remove those quotation marks, it then fails at “nil” – is there an solution to this?
Thank you.