gbudny93.RouterOS_Useful_Sc.../RouterOS_Script_Fetch.rsc

35 lines
1.2 KiB
Text
Raw Normal View History

2019-08-21 14:22:27 +02:00
# RouterOS Function
# Copyright (c) Grzegorz Budny
# Fetches RouterOS script from external https location and runs it or creates schedule task
:global FetchScript do={
2019-10-14 20:49:16 +02:00
:foreach url,destinationFileName in=$urls do={
2019-08-21 14:22:27 +02:00
2019-10-14 20:49:16 +02:00
/tool fetch mode=https http-method=get url=$url dst-path=($destinationPath."/".$destinationFileName);
:log info "...:::Scripts fetched:::...";
2019-08-21 14:22:27 +02:00
2019-10-14 20:49:16 +02:00
:if ($isRun) do={
2019-08-21 14:22:27 +02:00
2019-10-14 20:49:16 +02:00
/system script run ($destinationPath.$destinationFileName);
:log info "...:::Script loaded to environment:::...";
}
:if ($isSchedule) do={
2019-08-21 14:22:27 +02:00
2019-10-14 20:49:16 +02:00
/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:::...";
2019-08-21 14:22:27 +02:00
2019-10-14 20:49:16 +02:00
}
2019-08-21 14:22:27 +02:00
}
}
2019-10-14 20:49:16 +02:00
#Example
:global urlsBase {"URL1"="script1"; \
"URL2"="script2" \
};
2019-08-21 14:22:27 +02:00
2019-10-14 20:49:16 +02:00
$FetchScript urls=$urlsBase destinationPath="destinationPath" destinationFileName=$urlsBase;