Community discussions

MikroTik App
 
andya
newbie
Topic Author
Posts: 25
Joined: Thu Jun 08, 2017 10:32 am

Script for If enivorment = then do

Sun Jun 14, 2020 9:49 am

Hi Am try to figure out how to make a script that runs download file based on that status of environment value

here is the current code am try to get work

:global configserver "http://192.168.1.187//$macaddress/temp.rsc"
:global "provisioned-status" "no"
:if (($provisioned-status="no")) do={/tool fetch url= $configserver output=file}
:if (($provisioned-status="no")) do={:log info "download provision"}
:if (($provisioned-status="yes")) do={:log info "already provision"}


/tool fetch url= $configserver works fine to grab the config file maybe am missing some bracket or something any suggestions?
 
User avatar
mutluit
Forum Veteran
Forum Veteran
Posts: 821
Joined: Wed Mar 25, 2020 4:04 am

Re: Script for If enivorment = then do

Sun Jun 14, 2020 3:16 pm

Hi Am try to figure out how to make a script that runs download file based on that status of environment value

here is the current code am try to get work

:global configserver "http://192.168.1.187//$macaddress/temp.rsc"
:global "provisioned-status" "no"
:if (($provisioned-status="no")) do={/tool fetch url= $configserver output=file}
:if (($provisioned-status="no")) do={:log info "download provision"}
:if (($provisioned-status="yes")) do={:log info "already provision"}


/tool fetch url= $configserver works fine to grab the config file maybe am missing some bracket or something any suggestions?
Yeah, you have a blank after "url=" --> remove the blank.
And In the url you have double slashes after the IP --> should be just one slash.
 
andya
newbie
Topic Author
Posts: 25
Joined: Thu Jun 08, 2017 10:32 am

Re: Script for If enivorment = then do

Mon Jun 15, 2020 10:38 am

Hi ya the double slash was cause i edit the URL forgot to remove it had a folder name

I assume this what you meant for edit

:global "provisioned-status" "no"
:if (($provisioned-status="no")) do={/tool fetch url=$configserver output=file}
:if (($provisioned-status="no")) do={:log info "download provision"}
:if (($provisioned-status="yes")) do={:log info "already provision"}

still nothing the script run no error nothing logged in the systems logs
 
accarda
Member Candidate
Member Candidate
Posts: 208
Joined: Fri Apr 05, 2019 4:06 pm
Location: Italy

Re: Script for If enivorment = then do

Mon Jun 15, 2020 12:52 pm

Have you tried removing the quotation around the name of the global variable ??

:global "provisioned-status" "no" into :global provisioned-status "no"
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7053
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Script for If enivorment = then do

Mon Jun 15, 2020 1:11 pm

Variable name contains arithmetic character. I would suggest to avoid creating such variable names, but if you still do then remember that such names must be always in double quotes, like in this example:
:global "not-good-var-name" "x"
:put $"not-good-var-name"
 
andya
newbie
Topic Author
Posts: 25
Joined: Thu Jun 08, 2017 10:32 am

Re: Script for If enivorment = then do

Tue Jun 16, 2020 9:32 am

Thanks you both the name is was issues in bracket i change it to this now download it only issues is if i used yes it does not accept it as viable and change it it true? if low case but if caps it accepts it?? any suggestions on how do with only one like say no?

:global configserver "http://192.168.1.187/~andyasselin/$macaddress/temp.rsc"

:global "provisionedstatus" "no"
:if (($provisionedstatus="no")) do={/tool fetch url= $configserver output=file}
:if (($provisionedstatus="no")) do={:log info "download provision"}
:if (($provisionedstatus="yes")) do={:log info "already provision"}
 
msatter
Forum Guru
Forum Guru
Posts: 2912
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Script for If enivorment = then do

Tue Jun 16, 2020 1:40 pm

{
:global provisionedstatus false
:if $provisionedstatus do={} else={/tool fetch url= $configserver output=file; :log info "download provision"}
:if $provisionedstatus do={:log info "already provision"}
}
 
andya
newbie
Topic Author
Posts: 25
Joined: Thu Jun 08, 2017 10:32 am

Re: Script for If enivorment = then do

Wed Jun 17, 2020 5:36 am

Hi It works just curios why this won't work inside system scripts work at the console if run as script use /import says invalid URL not sure how to debug that i assume it same URL it pull for from $configserver not sure why won't run as a script any suggestions?
{
:global provisionedstatus false
:if $provisionedstatus do={} else={/tool fetch url= $configserver output=file; :log info "download provision"}
:if $provisionedstatus do={:log info "already provision"}
}
 
User avatar
mutluit
Forum Veteran
Forum Veteran
Posts: 821
Joined: Wed Mar 25, 2020 4:04 am

Re: Script for If enivorment = then do

Wed Jun 17, 2020 6:19 am

Hi It works just curios why this won't work inside system scripts work at the console if run as script use /import says invalid URL not sure how to debug that i assume it same URL it pull for from $configserver not sure why won't run as a script any suggestions?
{
:global provisionedstatus false
:if $provisionedstatus do={} else={/tool fetch url= $configserver output=file; :log info "download provision"}
:if $provisionedstatus do={:log info "already provision"}
}
I already told you the reason in posting #2: you have some excess blanks (space char)...
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script for If enivorment = then do

Wed Jun 17, 2020 7:44 am

Not ok:
:if $provisionedstatus do={} else={/tool fetch url=<space>$configserver output=file; :log info "download provision"}
OK:
:if $provisionedstatus do={} else={/tool fetch url=$configserver output=file; :log info "download provision"}
 
andya
newbie
Topic Author
Posts: 25
Joined: Thu Jun 08, 2017 10:32 am

Re: Script for If enivorment = then do

Wed Jun 17, 2020 8:33 am

I should have said i did remove the space it still wont run as script under
Not ok:
:if $provisionedstatus do={} else={/tool fetch url=<space>$configserver output=file; :log info "download provision"}
OK:
:if $provisionedstatus do={} else={/tool fetch url=$configserver output=file; :log info "download provision"}
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script for If enivorment = then do

Wed Jun 17, 2020 9:17 am

I think its the else that makes problem.
Can not see in your script that you have set the macaddress. All variables needs to be set or declared.
Do not use global variable if you do not need it. Only when passing data from one script to another or store the variable for later use.
Even then you need to declare the global variable before use.
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if $provisionedstatus do={/tool fetch url=$configserver output=file; :log info "download provision"}
}
Or
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if ($provisionedstatus=true) do={/tool fetch url=$configserver output=file; :log info "download provision"}
}
Or
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if ($provisionedstatus=false) do={/tool fetch url=$configserver output=file; :log info "download provision"}
}
 
andya
newbie
Topic Author
Posts: 25
Joined: Thu Jun 08, 2017 10:32 am

Re: Script for If enivorment = then do

Wed Jun 17, 2020 11:45 am

Thanks will give them try tomorrow to let you know I feel like with this code am get closed to what i want to do
maybe I should probably try the script use the sn vs mac address just to test that I was testing on a virtual machine so it did not have sn to use
now test on hap ac as said the script fun fine pasted into the cli terminal window but it doesn't run as import script or system script I am going try it maybe I cant use fetch in system script seem odd would have figured that script should have work in both system script and cli if was go to work



sorry i am set the mac via script

#/interface ethernet get ether1 mac-address
:log info "ethernet-mac-to-viable"
:global macaddress [/interface ethernet get ether1 mac-address]



and this does work at cli to fetch the file
I think its the else that makes problem.
Can not see in your script that you have set the macaddress. All variables needs to be set or declared.
Do not use global variable if you do not need it. Only when passing data from one script to another or store the variable for later use.
Even then you need to declare the global variable before use.
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if $provisionedstatus do={/tool fetch url=$configserver output=file; :log info "download provision"}
}
Or
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if ($provisionedstatus=true) do={/tool fetch url=$configserver output=file; :log info "download provision"}
}
Or
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if ($provisionedstatus=false) do={/tool fetch url=$configserver output=file; :log info "download provision"}
}
 
andya
newbie
Topic Author
Posts: 25
Joined: Thu Jun 08, 2017 10:32 am

Re: Script for If enivorment = then do

Mon Jun 22, 2020 8:52 am

any idea why they would not work as system scripts?

your sample with log on one and download does work I used your mac address field viable
 
andya
newbie
Topic Author
Posts: 25
Joined: Thu Jun 08, 2017 10:32 am

Re: Script for If enivorment = then do

Thu Jun 25, 2020 7:31 am

Hi Any idea why won't run a system script?
Thanks will give them try tomorrow to let you know I feel like with this code am get closed to what i want to do
maybe I should probably try the script use the sn vs mac address just to test that I was testing on a virtual machine so it did not have sn to use
now test on hap ac as said the script fun fine pasted into the cli terminal window but it doesn't run as import script or system script I am going try it maybe I cant use fetch in system script seem odd would have figured that script should have work in both system script and cli if was go to work



sorry i am set the mac via script

#/interface ethernet get ether1 mac-address
:log info "ethernet-mac-to-viable"
:global macaddress [/interface ethernet get ether1 mac-address]



and this does work at cli to fetch the file
I think its the else that makes problem.
Can not see in your script that you have set the macaddress. All variables needs to be set or declared.
Do not use global variable if you do not need it. Only when passing data from one script to another or store the variable for later use.
Even then you need to declare the global variable before use.
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if $provisionedstatus do={/tool fetch url=$configserver output=file; :log info "download provision"}
}
Or
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if ($provisionedstatus=true) do={/tool fetch url=$configserver output=file; :log info "download provision"}
}
Or
{
:local macaddress xx.xx.xx.xx
:local configserver "http://192.168.1.187/$macaddress/temp.rsc"
:local provisionedstatus false
:if ($provisionedstatus=false) do={/tool fetch url=$configserver output=file; :log info "download provision"}
}

Who is online

Users browsing this forum: No registered users and 34 guests