gbudny93.RouterOS_Useful_Sc.../RouterOS_Script_Fetch.rsc
Grzegorz Budny 69ab2f58ca Update
2019-10-14 20:49:16 +02:00

35 lines
No EOL
1.2 KiB
Text

# RouterOS Function
# Copyright (c) Grzegorz Budny
# Fetches RouterOS script from external https location and runs it or creates schedule task
:global FetchScript do={
:foreach url,destinationFileName in=$urls do={
/tool fetch mode=https http-method=get url=$url dst-path=($destinationPath."/".$destinationFileName);
:log info "...:::Scripts fetched:::...";
:if ($isRun) do={
/system script run ($destinationPath.$destinationFileName);
:log info "...:::Script loaded to environment:::...";
}
:if ($isSchedule) do={
/system scheduler \
add interval=($interval.h) name=$taskName on-event=("system script run ".($destinationPath."/".$destinationFileName)) \
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=jan/01/1970 start-time=$startTime;
:log info "...:::Script joined to scheduler:::...";
}
}
}
#Example
:global urlsBase {"URL1"="script1"; \
"URL2"="script2" \
};
$FetchScript urls=$urlsBase destinationPath="destinationPath" destinationFileName=$urlsBase;